Similar to an alphabet triangle, we can develop a C++ program to display a numerical triangle. This numerical triangle can be generated in various formats.
Let's explore an example in C++ to display a triangle of numbers.
Example
Example
#include <iostream>
using namespace std;
int main()
{
int i,j,k,l,n;
cout<<"Enter the Range=";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n-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:
Output
Enter the Range=5
1
121
12321
1234321
123454321
Example
Enter the Range=6
1
121
2321
1234321
123454321
12345654321