Learn C with example
Print Number Triangle Using 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 1 in first
line, 2 2 in second line 3 3 3 in third line ,and so on...
Source Code Of the Example
/* 1
2 2
3 3 3
4 4 4 4
5 5 5 5 5 */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter a number\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d",i);
printf("\n");
}
getch();
}
|
Output Of Example
| Enter a number
5 1
2 2
3 3 3
4 4 4 4
5 5 5 5 5 |