Floyd's triangle

C program for Floyd’s triangle Number pattern using nested for

C program for Floyd’s triangle Number pattern using nested for

In this tutorial, we will discuss C program for Floyd’s triangle Number pattern using nested for

floyd’s triangle in C language

In C language, we will discuss about Floyd’s triangle Number pattern using nested for in C programming language.

In C language, we can display many shapes such as Floyd’s triangle ,pyramids, rectangles and squares etc…

In this post, we display floyd’s triangle number pattern using Nested for loop in C language

Program to print triangle pattern using number

Code to floyd’s triangle pattern 1

Program 1

#include <stdio.h>
#include <stdlib.h>

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

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

Enter number of rows
7
1
12
123
1234
12345
123456
1234567

Program 2

#include <stdio.h>
#include <stdlib.h>

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

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

Enter number of rows
7
1
22
333
4444
55555
666666
7777777

Code to floyd’s triangle pattern 2

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j;
    printf("Enter number of rows\n");
    scanf("%d", &rows);
    for(i=rows; i>=1; i--){
        for(j=1; j<=i; j++){
        printf("%d",j);
    }
    printf("\n");
    }
    getch();
    return 0;
}

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

Enter number of rows
7
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

 

Code to floyd’s triangle pattern 3

Program 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j;
    printf("Enter number of rows\n");
    scanf("%d", &rows);
    for(i=rows; i>=1; i--){
        for(j=1; j<=i; j++){
        printf("%d",i);
    }
    printf("\n");
    }
    getch();
    return 0;
}

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

Enter number of rows
7
7777777
666666
55555
4444
333
22
1

Code to floyd’s triangle pattern 4

Program 5

#include <stdio.h>
#include <stdlib.h>

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

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

Enter number of rows :7
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28

Code to floyd’s triangle pattern 5

 

Program 6

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j;
    printf("Enter number of rows :");
    scanf("%d", &rows);
    for(i=1; i<=rows; i++){
        for(j=rows; j>=1; j--){
                if(j<=i)
        printf("%d",j);else
            printf(" ");
    }
    printf("\n");
    }
    getch();
    return 0;
}

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

            1
          21
        321
      4321
    54321
  654321
7654321

Program 7

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j,k=1,l=1;
    printf("Enter number of rows :");
    scanf("%d", &rows);
    for(i=1; i<=rows; i++){
            l=k;
        for(j=1; j<=i; j++){
            printf("%d",l++);
            k=l--;
    for(j=1; j<i; j++){
        printf("%d",--l);}}
            printf("\n");

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


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

1
21
321
4321
54321
654321
7654321

Code to floyd’s triangle pattern 6

Program 8

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j,k=1,l=1;
    printf("Enter number of rows :");
    scanf("%d", &rows);
    for(i=1; i<=rows; i++){
            l=k;
        for(j=1; j<=i; j++)
            printf("%d",l++);
            k=l--;
    for(j=1; j<i; j++)
        printf("%d",--l);
            printf("\n");

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


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

Enter number of rows :4

1
232
45654
78910987

 

Code to floyd’s triangle pattern7

 

Program 9

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j,k;
    printf("Enter number of rows :");
    scanf("%d", &rows);
    k=1;
    for(i=1; i<=rows; i++){
        for(j=rows; j>=1; j--){
                if(j>i)
            printf("   ");else
        printf("%3d",k++);
        }

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



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

                          1
                       2 3
                    4 5 6
                7 8 9 10
     11 12 13 14 15
16 17 18 19 20 21

Program 10

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rows,i,j,k;
    printf("Enter number of rows :");
    scanf("%d", &rows);
    k=1;
    for(i=1; i<=rows; i++){
        for(j=rows; j>=i; j--){
        printf("%3d",k++);
        }

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

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

Enter number of rows :5
 1  2  3  4  5  6 
 7  8  9 10 11 
12  13 14 15
16  17 18
19  20
21

 

Suggested for you

for loop in Java language

for loop in C++ language

for loop in C language

for loop in Python language

 

Floyd's triangle Number pattern using nested for in Java
Floyd's triangle number pattern Using nested while loop in Java
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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago