## Print Floyd's triangle in C

In this article we will see some c program to print Floyd’s triangle. We will take the row number from the user and print the Floyd’s triangle. Suppose a user gives the input 4 as the input. Then we will print the Floyd’s triangle which have 4 rows like bellow.

1

2 3

4 5 6

7 8 9 10

A Floyd triangle which has n row, the nth row contains n numbers and total numbers in the triangle of n rows are = n * (n + 1) / 2

## Program to print Floyd's triangle in C

``````// program to print Floyd's triangle in C
#include <stdio.h>
int main(){
int x, y, num, z = 1;

printf("Enter number of rows for Floyd's triangle : ");
scanf("%d", &num);

for (x = 1; x <= num; x++){

for (y = 1; y <= x; y++){
printf("%d ", z);
z++;
}

printf("\n");
}

return 0;
}``````

## C program to print Floyd triangle using recursion

``````// C program to print Floyd's triangle using recursion
#include <stdio.h>
void printFloyd(int a, int b, int c){
int i;

if (a > b)
return;

for (i = 1; i <= a; i++){
printf("%d ", c++);
}
printf("\n");
printFloyd(++a, b, c);
}

int main(){
int num;

printf("Input number of rows here : ");
scanf("%d", &num);

printFloyd(1, num, 1);

return 0;
}``````

### See output of this Floyd's triangle program:

Previous page:Â  Pattern printing programs

Next page:Â  Pascal triangle by C