C Programming |
Positive-Negative Number Triangle Posted: 06 Sep 2013 11:15 AM PDT Q. Write a C program to print the following positive-negative number triangle as: 9 8 6 7 5 3 4 2 0 -2 1 -1 -3 -5 -7 Ans. /*c program for positive-negative number triangle*/ #include<stdio.h> int main() { int num,n,r,c; for(r=1,num=9; r<=5; r++,num--) { if(r==4) { for(c=1,n=4; c<=r; c++,n=n-2) printf(" %d",n); } else if(r==5) { for(c=1,n=1; c<=r; c++,n=n-2) printf(" %d",n); } else { for(c=1,n=num; c<=r; c++,n=n-2) printf(" %d",n); } printf("\n"); } getch(); return 0; } /*************************************************************** The output of above positive-negative number triangle C 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