Floyd's triangle

C program to reverse triangle number patterns using while loop

C program to reverse triangle number patterns using while loop

In this tutorial, we will discuss the concept of C program to reverse triangle number patterns using while loop

In C language, we can use for loop, while loop, do-while loop to display various number, star, alphabet and binary number patterns

In this topic, we demonstrate how to display some reversed number patterns using the nested while loop in C language.

 

 

Pattern 1

Reverse number pattern 1

Reverse triangle number pattern 1

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

int main()
{
    int j,rows;//variable declaration
    printf("Enter the number of rows:\n ");
    scanf("%d",&rows);//take input from user
    printf("\n");

    while(rows>=1){//outer while loop
        int j=rows;
        while(j>=1){//inner while loop
            printf("%d",j);//Display pattern
            j--;
        }
        rows--;
    printf("\n");//move to next line
    }
    getch();
    return 0;
}

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

Enter the number of rows:
8

87654321
7654321
654321
54321
4321
321
21
1

 

Pattern 2

Reverse number pattern 2

Reverse triangle number pattern 2

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

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

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

Enter the number of rows: 8

88888888
7777777
666666
55555
4444
333
22
1

 

Suggested for you

For loop in C language

while loop in C language

Nested while loop in C language

Operator in C language

Reverse order number pattern in C using for loop
Reverse order number pattern in Cpp using for loop
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…

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