Floyd's triangle

C program to triangle number pattern

C program to triangle number pattern

In this tutorial, we will discuss how to write following C program to triangle number pattern

Here, some of Floyd’s triangle number patterns are written using nested for loop in C language

Program 1

Code to triangle number pattern 1

Triangle number pattern 1
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows;
    printf("Triangle pattern 1\n\n");
    printf("Enter the rows: ");
    scanf("%d",&rows);
    int i,j;
    for(i=1; i<=rows; i++)
    {
        for(j=i; j<=rows; j++)
    {
        printf("%d",i);
    }
      printf("\n");
    }
   getch();
    return 0;
}

When the above code is executed, it produces the following results:

11111111
2222222
333333
44444
5555
666
77
8

 

Program 2

Code to triangle number pattern 2

Triangle number pattern 2
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows;
    printf("Triangle pattern 1\n\n");
    printf("Enter the rows: ");
    scanf("%d",&rows);
    int i,j;
    for(i=1; i<=rows; i++)
    {
        for(j=i; j<=rows; j++)
    {
        printf("%d",j);
    }
      printf("\n");
    }
   getch();
    return 0;
}

When the above code is executed, it produces the following results:

12345678
2345678
345678
45678
5678
678
78
8

 

Program 3

Code to triangle number pattern 3

Triangle number pattern 3
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows;
    printf("Triangle pattern 3\n\n");
    printf("Enter the rows: ");
    scanf("%d",&rows);
    int i,j,k;
    for(i=rows; i>=1; i--)
    {
        if(i%2==1){k=1;
        }
        else {k=i;}
        for(j=1; j<=i; j++)
    {
        printf("%d",k);
        if(i%2==1){k++;}
        else {k--;}

    }
      printf("\n");
    }
   getch();
    return 0;
}

When the above code is executed, it produces the following results:

87654321
1234567
654321
12345
4321
123
21
1

 

Program 4

Code to triangle number pattern 4

Triangle number pattern 4
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows, i,j,k=1;
    printf("Enter the rows for pattern: ");
    scanf("%d",&rows);           //input from user
    printf("here your pattern\n");
    for(i=1; i<=rows; i++){   //for rows
        for(j=1; j<=i; j++){
        printf("%d",k);
        k++;
    }
    k--;
    for(j=1; j<=i-1; j++){
k--;
            printf("%d",k);
    }


        printf("\n");
        k=1;
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Enter the rows for pattern:9
here your pattern
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321

 

Suggested for you

For loop in Java language

For loop in C++ language

For loop in C language

For loop in Python language

 

While loop in Java language

While loop in C language

While loop in C++ language

While loop in Python language

 

Do-while loop in Java language

Do-while loop in C language

Do-while loop in C++ language

 

Similar post

Java program to print star pyramid pattern 

C program to print star pyramid pattern 

C++ program to print star pyramid pattern 

Python program to print star pyramid pattern 

Floyd’s triangle number pattern using for loop in C

Floyd’s triangle pattern using nested for loop in Java

Floyd’s triangle pattern using nested while loop in Java

 

C program to pyramid number pattern
C program to Inverted pyramid number pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago