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

Similar post

Similar post

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

Hollow pyramid triangle pattern in C++ language

Pyramid star pattern in Cpp

Pyramid star pattern in C

Pyramid star pattern in Java 

Rhombus pattern in Java using for loop

Rhombus pattern in C using while loop

Rhombus pattern in C++ using do-while loop

 

Suggested for you

for loop in Java

while loop in Java

for loop in C language

while loop in C language

while loop in cpp language

For loop in Cpp language

Nested for loop in Java

Nested for loop in C++

Nested for loop in C

Nested for in  Python

 

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

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…

1 month 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…

1 month ago