Solution: Display a Triangle

Solution: Display a Triangle

C
#include <stdio.h>
int main(void)
{
int n = 6;
int i, j;
// Each iteration prints row i
for (i = 1; i <= n; i++)
{
// Print n-i spaces in row i
for (j = 0; j < (n-i); j++)
{
printf(" ");
}
// Print 2*i-1 asterisks in row i
for(j = (n - i); j < (n - i) + (2 * i - 1); j++)
{
printf("*");
}
printf("\n");
}
return 0;
}