Q) Write a C program to print the following :-
1
2 3
4 5 6
7 8 9 1
2 3 4 5 6
Sol)
#include<stdio.h>
void pyramid(int ); //prototype
int main( )
{
int num;
printf(" Enter the number of rows : ") ;
pyramid(num) ; // Call
return 0;
}
void pyramid(int n ) //definition
{
int r,c,x=1,y=1;
for(r=1;r<=n; r++)
{
for(c=1; c<=r; c++,x++)
{
if(x<=9)
printf("%d", x);
else
{
printf("%d", y);
y++;
}
}
printf("\n");
}
}
No comments:
Post a Comment