Monday, December 17, 2012

Number Pyramid

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

1
123
12345
1234567

Ans.

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

 int num,r,c,p=1;
 printf("Enter number of rows: ");
 scanf("%d", &num);
 for(r=1; r<=num; r++,p=p+2)
 {
  for(c=1; c<=p; c++)
    printf("%d",c);
  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

No comments:

Post a Comment