We intend to make a program which accepts the number of rows from user and display a triangular pattern like below:
1
a b
2 3 4
c d e f
5 6 7 8 9
PROGRAM
// Program to display alphanumeric triangle
#include <iostream>
using namespace std;
int main()
{
int n,i,j,k=1;
char ch='a';
cout<<"\nENTER NUMBER OF ROWS: ";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%2)
{
cout<<k<<" ";
k++;
}
else
{
cout<<ch<<" ";
ch++;
}
}
cout<<endl;
}
return 0;
}
OUTPUT