DEV Community

Cover image for Nested for loop in C++(critical)
Saiful Islam
Saiful Islam

Posted on

Nested for loop in C++(critical)

The problem is about, have to take a user input as int, to see the ASCII value output per row times.
Image description
Image description
The code is given here:

#include<iostream>
using namespace std;
int main()
/*
a
bb
ccc
dddd
eeeee
*/
{
    int row, col,n;
    cout<<"Enter the 'n' number to see the magic:" <<endl;
    cin>>n;
    for(row=1;row<=n;row++)
    {
        char name='a'+row-1;
//here,a's ascii value is 96;then row's value addition changes output//
        for(col=1;col<=row;col++)
        {
            cout<<name<<" ";
        }
        cout<<endl;
    }
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

As example:
If, Input=4
Then, Output=
a
bb
ccc
dddd
(Speciality is input when exceeds the alphabetic number 26. Then, output shows as per ASCII value.)

Top comments (0)