In this, we are going to see how to print the above pattern of inverted triangle of numbers, using nested for loops in C++.
The code given below can be used for TURBO C++ Compiler:-
// pattern 13
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,j;
cout<<"Enter rows \n";
cin>>n;
for(i=n;i>=1;i--)
{
for(j=i;j>=1;j--)
{
cout<<j;
}
cout<<"\n";
}
getch();
}
The code given below can be used for g++/gcc Compiler:-
// pattern 13
#include<iostream>
using namespace std;
int main()
{
int n,i,j;
cout<<"Enter rows \n";
cin>>n;
for(i=n;i>=1;i--)
{
for(j=i;j>=1;j--)
{
cout<<j;
}
cout<<"\n";
}
return 0;
}
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP