C Programming |
Posted: 15 May 2013 03:03 AM PDT Q. Write a C program to print the following nested pyramid as: * *** *** * ** ** ** ** *** * * *** Ans. /*c program for nested pyramid*/ #include<stdio.h> int main() { int r,c,num=3,n; n=num; for(r=1; r<=num; r++,n--) { for(c=1; c<=r; c++) printf("*"); printf(" "); for(c=n; c>=1; c--) printf("*"); printf(" "); for(c=n; c>=1; c--) printf("*"); printf(" "); for(c=1; c<=r; c++) printf("*"); printf("\n"); } getch(); return 0; } The output of above program would be:
| ||
Posted: 15 May 2013 02:26 AM PDT Q. Write a C program to print the following character pyramid as: a b b b b a b b b b a b b b b a Ans. /*c program for alternate character pyramid*/ #include<stdio.h> int main() { char r,c,ch='d'; for(r='a'; r<=ch; r++) { for(c='a'; c<=ch; c++) { if(r==c) printf(" a"); else printf(" b"); } printf("\n"); } getch(); return 0; } The output of above program would be:
Related program: 1. Print the following dignal number pyramid: 1 2 2 2 2 1 2 2 2 2 1 2 2 2 2 1 | ||
Posted: 15 May 2013 02:28 AM PDT Q. Write a C program to print the following double number pyramid as: 1222 2122 2212 2221 Ans. /*c program for alternate number pyramid*/ #include<stdio.h> int main() { int r,c,num=4; for(r=1; r<=num; r++) { for(c=1; c<=num; c++) { if(c==r) printf("1"); else printf("2"); } printf("\n"); } getch(); return 0; } The output of above program would be:
Related program: 1. Print the dignal character pyramid as: a b b b b a b b b b a b b b b a |
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