In this tutorial, we will discuss the Inverted Pyramid number pattern in Cpp language
In this topic, we will learn about how to create an Inverted Pyramid number pattern in C++ using for loop or nested for loop
Pattern 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,k,rows,count1,temp,num; cout<<"Enter the number of rows: "; cin>>rows;//get input from user for number rows cout<<"Here your pattern: \n"; count1=1; temp=1+(rows-1)*2; for(i=1; i<=rows; i++){ //parent for loop to iterates row num=1; for(j=1; j<=count1; j++){//print space in biginning cout<<" "; } for(k=temp; k>=1; k--){ cout<<num;//print number for pattern num++; } count1++; temp=temp-2; cout<<"\n"; } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 5 Here your pattern: 123456789 1234567 12345 123 1
Pattern 2
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,k,rows; int count1=1, num; cout<<"Enter the number of rows: "; cin>>rows;//get input from user for number of rows cout<<"Here your pattern: \n"; count1=1; num=1+(rows-1)*2; for(i=1; i<=rows; i++){//outer for loop for iterate row for(j=1; j<=count1; j++){//inner for loop to print space cout<<" "; } for(k=num; k>=1; k--){//inner for loop for print number cout<<i; } count1++; num=num-2; cout<<"\n"; } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 5 Here your pattern 111111111 2222222 33333 444 5
Pattern 3
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,rows,space=0; int count1=1, num; cout<<"Enter the number of rows: "; cin>>rows;//get input from user for pyramid cout<<"Here your pattern: \n"; for(i=rows; i>=1; i--){//outer for loop for iterate row for(j=1; j<=space; j++)//inner for loop to print space cout<<" "; for(j=1; j<=i; j++)//print right side of piramid cout<<j; for(j=i-1; j>=1; j--)//print right side of piramid cout<<j; cout<<"\n"; space++; } getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 6 Here your pattern: 12345654321 123454321 1234321 12321 121 1
Suggested for you
Nested for loop in C++language
Data type in C++ language
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,…