Print Triangle Pattern of Numbers and Stars in C
Notes:
Print Triangle Pattern of Numbers and Stars in C Programming:
Displaying stars and numbers in triangle shape or triangle pattern in C:
Ex1:
int row=0;
int col=0;
int totalRows=4;
for(row=1; row<=totalRows; row++)
{
for(col=1; col<=row; col++)
{
printf("* ");
}
printf("\n");
}
Output:
*
* *
* * *
* * * *
Ex2:
int row=0;
int col=0;
int totalRows=4;
for(row=1; row<=totalRows; row++)
{
for(col=1; col<=row; col++)
{
printf("%d ",row);
}
printf("\n");
}
Output:
1
2 2
3 3 3
4 4 4 4
Ex3:
int row=0;
int col=0;
int totalRows=4;
for(row=1; row<=totalRows; row++)
{
for(col=1; col<=row; col++)
{
printf("%d ",col);
}
printf("\n");
}
Output:
1
1 2
1 2 3
1 2 3 4