In this tutorial, we will discuss a concept of Reverse order number pattern in Cpp using for 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 for loop in Cpp language.
Pattern 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,rows;//variable declaration cout<<"Enter the number of rows: "; cin>>rows;//Take input the number of rows from user cout<<"\n"; for(i=1; i<=rows; i++){ for(j=i; j>=1; j--){ cout<<j;//Display pattern } cout<<"\n";//move to next line } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 8 1 21 321 4321 54321 654321 7654321 87654321
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,rows;//variable declaration cout<<"Enter the number of rows: "; cin>>rows;//Take input the number of rows from user for( i=rows; i>=1; i--){ for( j=rows; j>=i; j--){ cout<<j<<" "; } cout<<"\n";//move to next line } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 8 8 8 7 8 7 6 8 7 6 5 8 7 6 5 4 8 7 6 5 4 3 8 7 6 5 4 3 2 8 7 6 5 4 3 2 !
Pattern 3
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,rows;//variable declaration cout<<"Enter the number of rows: "; cin>>rows;//Take input the number of rows from user for(i=rows; i>=1; i--){//outer loop for(j=i; j>=1; j--){//inner loop cout<<i<<" "; } cout<<"\n";//move to next line } return 0; }
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 7 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…
View Comments
Thank you so much you save my life....