Saturday, January 25, 2014

Number Decrease to Zero Triangle

Q. Write a C program to print the following number decrease to zero triangle pattern as:

     0
    101
   21012
  3210123
 432101234

Ans.

/*c program for number decrease triangle*/
#include<stdio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter max number : ");
 scanf("%d", &num);
 for(r=0; r<=num; r++)
 {
   for(sp=r; sp<num; sp++)
       printf(" ");
   for(c=r; c>=0; c--)
       printf("%d",c);
   for(c=1; c<=r; c++)
       printf("%d",c);
   printf("\n");
 }
 getch();
 return 0;
}

/************************************************************
The output of above program would be:
************************************************************/

Output of Number Decrease to Zero Triangle C program
Figure: Screen shot for Number Decrease to Zero Triangle C program

No comments:

Post a Comment