C Programming |
Nested Number Character Pyramid Posted: 26 Mar 2014 04:51 AM PDT Q. Write a C program to print the following nested number-character pyramid/pattern as: A 1 BB 22 CCC 333 Ans. /*c program for nested number character pyramid*/ #include<stdio.h> int main() { int num,r,c,z,n=1; char ch='A'; printf("Enter Maximum number : "); scanf("%d", &num); for(r=1; r<=num; r++,ch++,n++) { for(c=1; c<=2; c++) { if(c%2==0) { for(z=1; z<=r; z++) printf("%d",n); } else { for(z=1; z<=r; z++) printf("%c",ch); } printf("\n"); } } getch(); return 0; } /************************************************************** The output of above program would be: **************************************************************/
Related programs: 1. Nested same Symbol Pyramid as: # # ## ## ### ### 2. Nested Differ Symbol Pyramid as: @ # @@ ## @@@ ### 3. Nested Equal same-equal Pyramid as: @ @ ## ## @@@ @@@ 4. Nested Equal Number Pyramid as: 1 1 22 22 333 333 5. Nested Differ Character Pyramid as: A A BB BB CCC CCC |
You are subscribed to email updates from C Programming To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
Post a Comment