C Program to Display Floyd’s triangle


This is a C Program to display floyd’s triangle.

Problem Description

This C Program displays floyd’s triangle.

Problem Solution

It displays floyd’s triangle as shown in the program below.

Program/Source Code

Here is source code of the C Program to display floyd’s triangle.The C program is successfully compiled and run on a Linux system. The program output is also shown below.

 * C Program to Display Floyd’s triangle
#include <stdio.h>
main( )
    int i, j, k = 1;
    printf("floyds triangle is\n");
    for( i = 1; k <= 20; ++i )
        for( j = 1; j <= i; ++j )
	    printf( "%d ", k++ );
	    printf( "\n\n" );
    return 0;
Program Explanation

This C program is used to print Floyd’s triangle. Floyd’s triangle is a right-angled triangular array of natural numbers. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner: 1. Number of rows of Floyd’s triangle to print is entered by the user. For loop is used to print the output of the program.

Runtime Test Cases
$ cc pgm36.c
$ a.out
floyds triangle is
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn