Learn C with example
Print Number Triangle in C
In this example we are going to make a program by which
we can Print numeric Triangle.
In this example we are going to print a number
triangle. In this number triangle we have 1 in first row,1 2 in second row ,1 2
3 in third row and so on....
Source Code of Example
/* print the */
#include<stdio.h> /* 1 */
#include<conio.h> /* 1 2 */
void main() /* 1 2 3 */
{ /* 1 2 3 4 */
int i,j,n; /* 1 2 3 4 5 */
clrscr();
printf("Enter the number\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
getch();
}
|
Output Of Example
| Enter a number
5 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 |