Saturday, 28 May 2016

Write a program that displays the following output using loop:

A
A   B
A   B   C
A   B   C   D
A   B   C   D   E

Solution:

#include<iostream.h>
#include<conio.h>
void main()
{
     int  i,j;
     char ch='A'
     for ( i= 1; i<=5; i++)
     {
          for(j=1; j<=i; j++)
            { if (j==1) ch= 'A';
            cout<<ch++; }
    cout<<endl;
    }
    getch();
}

No comments:

Post a Comment