Saturday, August 9, 2014

Number Triangle Pattern C Program

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

0
101
21012
3210123
432101234
54321012345

Ans.


/*c program for number triangle pattern*/
#include<stdio.h>
int main()
{

 int num,r,c,m,n;
 printf("Enter maximum number : ");
 scanf("%d", &num);
 for(r=1,m=0; r<=num+1; r++,m++)
 {
   for(c=1,n=m; c<=r; c++,n--)
       printf("%d", n);
   for(c=1; c<r; c++)
       printf("%d", c);
   printf("\n");
 }
 getch();
 return 0;
}

/*************************************************************
The output of above number triangle pattern program as
************************************************************/

Output for Number Triangle Pattern C Program
Figure: Screen shot for Number Triangle Pattern C program

    No comments:

    Post a Comment