C Programming |
Equilateral Triangle Number Design Posted: 05 Sep 2013 10:12 AM PDT Q. Write a C program to print the following equilateral triangle number design as: 5 454 34543 2345432 123454321 Ans. /*c program for equilateral triangle design*/ #include<stdio.h> int main() { int num,r,c,sp,n; printf("Enter no. of rows : "); scanf("%d", &num); for(r=1; r<=num; r++) { for(sp=num-r; sp>=1; sp--) printf(" "); for(n=num-r+1; n<=num; n++) printf("%d",n); for(c=1,n=num-1; c<r; c++,n--) printf("%d",n); printf("\n"); } getch(); return 0; } The output of above program would be:
| ||
Posted: 05 Sep 2013 08:18 AM PDT Q. Write a C program to print the Z-Shape pyramid as: ****** * * * * ****** Ans. /*c pyramid program for z-shape*/ #include<stdio.h> int main() { int num,r,c,sp,n; printf("Enter no. of rows : "); scanf("%d", &num); for(r=1; r<=num; r++) printf("*"); printf("\n"); for(r=1,n=num-1; r<=num-2; r++,n--) { for(sp=1; sp<n; sp++) printf(" "); printf("*"); printf("\n"); } for(r=1; r<=num; r++) printf("*"); printf("\n"); getch(); return 0; } The output of above program would be:
| ||
Posted: 05 Sep 2013 07:01 AM PDT Q. Write a C program to print the following number triangle as: 1 21 321 4321 54321 Ans. /*c program for number pyramid*/ #include<stdio.h> int main() { int num,r,c,sp; printf("Enter no of rows : "); scanf("%d", &num); for(r=1; r<=num; r++) { for(sp=num-r; sp>=1; sp--) printf(" "); for(c=r; c>=1; c--) printf("%d",c); printf("\n"); } getch(); return 0; } The output of above program would be:
|
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