Q. Write a C program to print the following number pyramid or Floyd triangle:
1
2 3
4 5 6
7 8 9 10
Ans.
/*c program to print the number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,sp,i=1;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<=num-r; sp++)
printf(" ");
for(c=1; c<=r; c++,i++)
printf("%d ",i);
printf("\n");
}
return 0;
}
The output of above program would be:
1
2 3
4 5 6
7 8 9 10
Ans.
/*c program to print the number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,sp,i=1;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<=num-r; sp++)
printf(" ");
for(c=1; c<=r; c++,i++)
printf("%d ",i);
printf("\n");
}
return 0;
}
The output of above program would be:
Figure: Screen shot for Floyd triangle C program |
1
ReplyDelete23
456
78910
456
23
1
To print this Wat should I do help me pls
@Praddos Kanna,
DeleteYour required pattern Floyd triangle C program source code at:
http://cprogrammingcodes.blogspot.com/2016/01/reverse-floyd-triangle-half-floyd.html