Q. Write a C program of Continuous Vertical Horizontal Number Pyramid design as:
1
6 2
10 7 3
13 11 8 4
15 14 12 9 5
Ans.
Before we starting the coding of above number pyramid design, let's focus the following source image of above pyramid:
So, In above pyramid design it is too easy to making every rows and columns. let's starting the writing source code.
/*c program for continuous vertical horizontal number pyramid*/
#include<stdio.h>
int main()
{
int r,c,a=1,b,y,z=5;
for(r=1; r<=5; r++, a=a+7-r, z--)
{
b=a;
y=z;
for(c=1; c<=r; c++, b=b-y++)
printf(" %d ",b);
printf("\n");
}
getch();
return 0;
}
You might also like:
1
6 2
10 7 3
13 11 8 4
15 14 12 9 5
Ans.
Before we starting the coding of above number pyramid design, let's focus the following source image of above pyramid:
Figure: Showing flow of data in Number Pyramid Design |
So, In above pyramid design it is too easy to making every rows and columns. let's starting the writing source code.
/*c program for continuous vertical horizontal number pyramid*/
#include<stdio.h>
int main()
{
int r,c,a=1,b,y,z=5;
for(r=1; r<=5; r++, a=a+7-r, z--)
{
b=a;
y=z;
for(c=1; c<=r; c++, b=b-y++)
printf(" %d ",b);
printf("\n");
}
getch();
return 0;
}
/**********************************************************
The output of above program would be:
***********************************************************/
Figure: Screen shot of How To Make Continuous Vertical Horizontal Number Pyramid C Program |
You might also like:
0 komentar:
Post a Comment