How to print Floyd's triangle in C

1 Answer

0 votes
#include <stdio.h> 
 
// Floyd's triangle is a right-angled triangular of natural numbers
 
int main(int argc, char **argv) 
{ 
    int i, j, rows = 7, n = 1;

    for (i = 1; i <= rows; i++)
    {
        for (j = 1; j <= i; j++, n++)
            printf("%d ",n);
        printf("\n");
    }
    
    return(0);
}
 
  
/*
  
run:
  
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
  
*/

 



answered May 15, 2017 by avibootz
...