Number Character Triangle Posted: 03 Jan 2013 01:38 AM PST Q. Write a C program to print the following number character triangle: 1 a21 ba321 cba4321 dcba54321 edcba Ans. /*c program for number character pyramid*/#include<stdio.h>int main(){ int num,n,r,c,sp; char p,rch='a'; printf("Enter no of rows: "); scanf("%d", &num); n=num; for(r=1; num>=r; r++,n--,rch++) { for(c=r; c>=1; c--) printf("%d",c); for(sp=0; sp<=n ;sp++) printf(" "); for(p=rch; p>='a'; p--) printf("%c",p); printf("\n"); } getch(); return 0;} The output of above program would be:
| Figure: Screen shot for number-character pyramid C program |
|
Post a Comment