Print Floyd Triangle C Program

By | December 17, 2015

C Program To Print Floyd Triangle

Learn How To Print Floyd Triangle in C Programming Language. It is important that we should know How A For Loop Works before getting further with the C Program Code.

About Floyd’s Triangle

Floyd’s Triangle is named after a famous mathematician Robert Floyd. The Floyd’s Triangle Algorithm consists of an Array of Natural Numbers in a Right-angled Triangular format. It consists of Consecutive Numbers, starting with 1 till the Limit entered by the User.

Also Read: C Program To Convert Numbers To Words

Note: This Code to Generate Floyd’s Triangle in C Programming has been compiled with GNU GCC Compiler and developed with gEdit Editor and Terminal in Linux Ubuntu Terminal Operating System.

Method 1: C Program To Print Floyd Triangle using For Loop

#include<stdio.h>

int main() 
{
    int limit, count, a, num = 1;
    printf("Enter The Limit:\t");
    scanf("%d", &limit);
    for (count = 1; count <= limit; count++)
    {
        for(a = 1; a <= count; a++) 
        {
            printf("%d ", num);
            num++;
        }
        printf("\n");
    }
    printf("\n");
    return 0;
}

Method 2: Display Floyd Triangle in C Programming using While Loop

#include<stdio.h>

int main() 
{
    int limit, count, a, num = 1;
    printf("Enter The Limit:\t");
    scanf("%d", &limit);
    count = 1;
    while(count <= limit)
    {
        a = 1;
        while(a <= count) 
        {
            printf("%d ", num);
            num++;
            a++;
        }
        count++;
        printf("\n");
    }
    printf("\n");
    return 0;
}

Also Read: C Program To Find Special Numbers

 

Output

C Program To Print Floyd Triangle

In case you get any Compilation Errors with this Code To Print Floyd Triangle in C Programming or if you have any doubt about it, let us know about it in the Comment Section below.

3 thoughts on “Print Floyd Triangle C Program

    1. Tushar Soni Post author

      You’re welcome! We hope that you understood the difference of implementation in For Loop and While Loop in this Floyd’s Triangle in C Language.

      Reply
  1. Maha Al Shahwani

    Merci beaucoup pour tous ces programmes C. Tu as beaucoup aidé pour mes examens.

    Reply

Let's Discuss