Q. Write a C program to print the following square number pyramid pattern as:
1 2 3 4 5
15 14 13 12
6 7 8
11 10
9
Ans.
/*c program for square number pyramid pattern*/
#include<stdio.h>
int main()
int r,c,s1=1,s2=15;
for(r=5; r>=1; r--)
{
if(r%2==0)
{
if(r%2==0)
{
for(c=1; c<=r; c++,s2--)
printf(" %d",s2);
}
}
else
{
for(c=1; c<=r; c++,s1++)
{
for(c=1; c<=r; c++,s1++)
printf(" %d",s1);
}
printf("\n");
}
getch();
return 0;
}
/**********************************************************
The output of above program would be:
*********************************************************/
No comments:
Post a Comment