Floyd triangle program in C

Written by

Namrata Jangid

Floyd’s Triangle:

The code for printing Floyd’s triangle is:

With special characters

#include <stdio.h>

int  main()

{

int  n, i,  c;

printf("Enter the number of rows: ");

scanf("%d", & amp; n);

printf("\n");

for  (i = 1; i & lt; = n; i++)

{

  for  (c = 1; c &amp; lt; = i; c++)

  {

     printf("*");

  }

  printf("\n");

}

return  0;

}

The output for the above code is:

Enter the number of rows:  7

**






With numbers

#include <stdio.h>

int  main()

{

int  n, i,  c, a = 1;

printf("Enter the number of rows: ");

scanf("%d", & amp; n);

printf("\n");

for  (i = 1; i & lt; = n; i++)

{

  for  (c = 1; c &amp; lt; = i; c++)

  {

     printf("%d ", a);

     a++;

  }

  printf("\n");

}

return  0;

}

The output for the above code is:

Enter the number of rows:  7

1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

16 17 18 19 20 21

22 23 24 25 26 27 28

Floyd triangle program in C