CPP program to print Number Triangle

The below program is to print the Number Triangle in CPP using loop.

Code:

#include <iostream.h>
using namespace std;
 
int main()
{  
int i,j,k,l;    
for(i=1;i<=5;i++)    
{    
for(j=1;j<=5-i;j++)    
{    
cout<<" ";    
}    
for(k=1;k<=i;k++)    
{    
cout<<k;    
}    
for(l=i-1;l>=1;l--)    
{    
cout<<l;    
}    
cout<<"\n";    
}    
return 0;  
}

Output

        1
       121
      12312
     1234123
    123451234
Please follow and like us:
Content Protection by DMCA.com