C PROGRAMMINGS


PREVIOUS                                                                                       NEXT

1. Design rectangle pyramid

Q. Write a program to generate a following structure?
               
                @@@@@
                @@@@@
                @@@@@
                @@@@@
                @@@@@
               
Ans.   

/* c program for symbol structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=1; c<=num; c++)
     printf("@");
  printf("\n");
 }
 getch();
 return 0;
}

/************* OUTPUT **************
Enter loop repeat number(rows): 5
                @@@@@
                @@@@@
                @@@@@
                @@@@@
                @@@@@
***********************************/

2. Design triangle pyramid

Q. Write a program to generate a following #'s triangle?

#
#
#
#
#

#
#
#
#


#
#
#



#
#




#
Ans.

/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r=1,c,sp;
 printf("Enter loop repeat number(rows): "); 
 scanf("%d",&num);
 for(; num>=1; num--,r++)
 {
  for(sp=r; sp>1; sp--)
     printf(" ");
  for(c=1; c<=num; c++)
    printf("#");
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
 ####
  ###
   ##
    #
***********************************/

4.Design triangle pyramid

Q. Write a program to generate a following #'s triangle?
                   
#




#
#



#
#
#


#
#
#
#

#
#
#
#
#
Ans.

/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=1; c<=r; c++)
     printf("#");
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5
#




#
#



#
#
#


#
#
#
#

#
#
#
#
#

***********************************/

5.Design triangle pyramid

Q. Write a program to generate a following @'s triangle?
                                       




@



@
@


@
@
@

@
@
@
@
@
@
@
@
@
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter loop repeat number(rows): "); 
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(sp=num-r; sp>=1; sp--)
     printf(" ");
  for(c=1; c<=r; c++)
     printf("@");
  printf("\n");
 }
 getch();
 return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5




@



@
@


@
@
@

@
@
@
@
@
@
@
@
@

***********************************/

6.Design numbers rectangle structure

Q. Write a program to generate a following numbers structure:
   (Where user entered number through keyboard, for example if num=5)

                        12345
                        12345
                        12345
                        12345
                        12345

Ans.

/* c program for number rectangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=1; c<=num; c++)
   printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5
                        12345
                        12345
                        12345
                        12345
                        12345

***********************************/

8.Design numbers rectangle structure

Q. Write a program to generate a following numbers structure:
   (Where user entered number through keyboard, for example if num=5)
                            55555
                            44444
                            33333
                            22222
                            11111

Ans.

/* c program for number structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): "); 
 scanf("%d",&num);
 for(r=num; r>=1; r--)
 {
  for(c=num; c>=1; c--)
     printf("%d",r);
  printf("\n");
 }
 getch();
 return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
                            55555
                            44444
                            33333
                            22222
                            11111

***********************************/              

10. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:
   (Where user entered number through keyboard, for example if num=5)

                        1
                        12
                        123
                        1234
                        12345
Ans.

/* c program for number triangle*/
#include<stdio.h>
//#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
     printf("%d",c);
  printf("\n");
 }
 //getch();
 return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5
                        1
                        12
                        123
                        1234
                        12345

***********************************/ 

PREVIOUS                                                                                                            NEXT

No comments:

Post a Comment