Q:

Floyd's triangle in C

0

Floyd's triangle in C

C program to print Floyd's triangle: a user inputs how many rows of the triangle to print. The first four rows of Floyd's triangle are:
1
2 3
4 5 6
7 8 9 10
In Floyd's triangle, the nth row contains n numbers. Total numbers in the triangle of n rows: n*(n+1)/2.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main()
{
  int n, i,  c, a = 1;

  printf("Enter the number of rows of Floyd's triangle to print\n");
  scanf("%d", &n);

  for (i = 1; i <= n; i++)
  {
    for (c = 1; c <= i; c++)
    {
      printf("%d ", a); // Please note space after %d
      a++;
    }
    printf("\n");
  }

  return 0;
}

output:

Enter the number of rows of Floyd's triangle to print

5

2 3 

4 5 6 

7 8 9 10 

11 12 13 14 15 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now