Showing posts with label number pyramid c program. Show all posts
Showing posts with label number pyramid c program. Show all posts

Sunday, 2 December 2012

Number Triangle Program

Q. Write a C program to print the following number triangle design:

1
232
34543
4567654

Ans.

/*c program for number triangle design*/
#include<stdio.h>
int main()
{

 int num,r,c,s,t,q;
 printf("Enter any number : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(c=r, s=r; c>=1; c--,s++)
     printf("%d", s);
  for(q=r-1,t=s-2; q>=1; q--,t--)
     printf("%d", t);
  printf("\n");
 }
 return 0;
}

The output of above program would be:


Output of number pyramid C program
Figure: Screen shot for number pyramid C program

Monday, 17 September 2012

Number Pyramid

Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

 5
 45
 345
 2345
 12345

Ans.

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


The output of above program would be:


Output of number pyramid C program
Screen shot for number pyramid C program

Number Pyramid

Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

 5
 454
 34543
 23454321
 123454321

Ans.

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


The output of above program would be:


Output of number triangle C program
Screen shot for number triangle C program

Number Triangle


Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

 9
 898
 78987
 6789876

Ans.

/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,num=9,n,i,j;
 n = num;
 for(r=1; r<=4; r++,n--)
 {
  for(i=n; i<=num; i++)
    printf("%d", i);
  for(j=num-1; j>=n; j--)
    printf("%d", j);
  printf("\n");
 }
 getch();
 return 0;
}


The output of above program would be:

Output of specific number pyramid C program
Screen shot for specific number pyramid C program

Saturday, 8 September 2012

Number Pyramid

Q. Write a C program to print the following number triangle.
or
Q. Write a C program to display the following number pyramid.

       1
      222
     33333
    4444444
   555555555

Ans.

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

/**************Output**************/

Output of number pyramid C program
Screen shot for number pyramid C program

Saturday, 28 July 2012

Number triangle

Q. Write a C program to print the following number triangle:


1
12
123
1234
12345
1234
123
12
1


Ans.


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


/**************Output**************/


Output of number pyramid C program
Screen shot for number triangle C program

Thursday, 26 July 2012

Number pyramid

Q. Write a C program to print the following number structure:


          1
         2 2
        3 3 3
       4 4 4 4
      5 5 5 5 5
     6 6 6 6 6 6


Ans.


/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,n=6;
 for(r=1; r<=6; r++)
 {
  for(sp=1; sp<=n; sp++)
     printf(" ");
  for(c=1; c<=r; c++)
  {
     printf("%d",r);
     printf(" ");
  }
  printf("\n");
  n=n-1;
 }
 getch();
 return 0;
}


/************Output************/


Output of number pyramid C program
Screen shot for number triangle C program

Tuesday, 24 July 2012

Number pyramid

Q. Write a C program to print the following number structure:


          1
         1 2
        1 2 3
       1 2 3 4
      1 2 3 4 5 
     1 2 3 4 5 6


Ans.


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


/************Output************/


Output of C program for number pyramid C program
Screen shot for number pyramid C program

Saturday, 7 July 2012

Number pyramid/triangle

Q. Write a C program to print the following number pyramid:

54321
 4321
  321
   21
    1

Ans.

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

/*********Output**********/
Output of C program for number triangle
Screen shot for number triangle