Number Pyramid/Triangle Posted: 16 Jun 2013 11:59 PM PDT Q. Write a C program to print the following number triangle as: 0010120123012340123012010 Ans. /*c program for number triangle*/#include<stdio.h>int main(){ int num,n,r,c,z; printf("Enter pyramid max number: "); scanf("%d", &num); for(r=0; r<=num; r++) { for(c=0,z=0; c<=r; c++,z++) printf("%d",z); printf("\n"); } for(n=num-1; n>=0; n--) { for(c=0,z=0; c<=n; c++,z++) printf("%d",z); printf("\n"); } getch(); return 0;} The output of above program would be:
| Figure: Screen shot for number pyramid C program |
|
Post a Comment