C Program Print Floyd Triangle

By | March 11, 2020

C Program Print Floyd Triangle

Floyd’s triangle is named after Rober Floyd. Floyd’s Triangle is a right angled triangle made of natural numbers.
First row contains only one number that is 1. Second row contains next to numbers, that is 2 and 3. Third row contains next 3 numbers that is 4, 5 and 6, and so on.

C Program Print Floyd Triangle

C Program Print Floyd Triangle

For rows =4 the Floyd’s Triangle

will be as follows:

1

2   3

4   5   6

7   8   9   10

/* C Program to print Floyd's Triangle
 if number of rows is 4 then the 
 output is as follows

1
2 3
4 5 6
7 8 9 10

*/
#include<stdio.h>

int main() {
    int nrows, i, j, number= 1;
    printf("Enter number of rows for printing Floyd's Triangle: ");
    scanf("%d", &nrows);
    
	for (i=1; i<=nrows; i++) 
	    {
          for (j=1; j<=i; ++j)
            { printf("%d ", number);
              number++;
            }
          printf("\n");
        }
    return 0;
}


Output

Enter number of rows for printing Floyd’s Triangle: 5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

 

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *