Thursday, May 15, 2014

Continuous Vertical Number Pyramid

Q. Write a C program to print the following continuous vertical number pyramid design as:

1
2  7 
3  8  13
4  9  14  19
5 10  15  20  25

Ans.


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

 int num,r,c,z,n;
 printf("Enter maximum no. of rows : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++,z=num)
 {
   for(c=1,n=r; c<=r; c++,n=n+z)
      printf("%d ",n);
   printf("\n");
 }
 getch();
 return 0;
}

/****************************************
The output of above program would be:
***************************************/

output of continuous vertical number pyramid C program
Figure: Screen shot for continuous vertical number pyramid C program


No comments:

Post a Comment