Thursday, August 22, 2013

Vertical Continues Number Pyramid

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

 1

 23
 4
 56
 7
 89
 10

Ans.

/*c program for vertical continues number pyramid*/
#include<stdio.h>
int main()
{
 int r,c,x,y;

 static int i=1;
 for(r=1; r<=7; r++)
 {
   if(r%2==0)
   {
     for(x=2; x>=1; x--,i++)
        printf("%d",i);
   }
   else
   {
     for(y=1; y>=1; y--,i++)
        printf("%d",i);
   }
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of Vertical Continues Number Pyramid C program
Figure: Screen shot for vertical continues number
 pyramid C program

No comments:

Post a Comment