2.18.2014

Number Triangle Pattern

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

1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9

Ans.

/*c program for triangle number pattern*/
#include<stdio.h>
int main()
{
 int num,r,c,q=1;
 for(r=1; r<=5; r++,q=q+2)
 {
  for(c=1; c<=q; c++)
     printf(" %d",c);
  printf("\n");
 }
 getch();
 return 0;
}


/**********************************************************
The output of above program would be:
***********************************************************/
Output of number triangle pattern C program
Figure: Screen shot for number triangle pattern C program

Related Programs:


1
1 4 9
1 4 9 16 25
1 4 9 16 25 36 49
1 4 9 16 25 36 49 64 81

No comments:

Post a Comment