C program to print inverted triangle
Write a c program to print following inverted triangle
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Program:
#include<stdio.h>
void main()
{
int i, j, n=1, k;
for(i=1; i<=5; i++)
{
for(k=2; k<=i; k++)
{
printf(" ");
}
for(j=5; j>=i; j--)
{
printf("%d ", n);
n++;
}
printf("\n");
n = 1;
}
}
Output:

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Program:
#include<stdio.h>
void main()
{
int i, j, n=1, k;
for(i=1; i<=5; i++)
{
for(k=2; k<=i; k++)
{
printf(" ");
}
for(j=5; j>=i; j--)
{
printf("%d ", n);
n++;
}
printf("\n");
n = 1;
}
}
Output:
Comments
Post a Comment