How to display character like this style? Enter N: 9 A B B C C C D D D D E E E E E f f f f g g g h h i

Display Character

HOME Forums Forum Display Character

This topic contains 3 replies, has 1 voice, and was last updated by  Voeurn Sothavith 1 year, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #904 Reply

    RaksmeyChea

    How to display character like this style?

    Enter N: 9

    A
    B B
    C C C
    D D D D
    E E E E E
    f f f f
    g g g
    h h
    i

    #905 Reply

    Pon Koemse
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
       int n,a=65,c=32;
       cout<<"Enter N : "; cin>>n;
       for(int i=1;i<=n;i++)
       {
          if(i<=n/2+1)
          {
             for(int j=1;j<=i;j++)
             {
                cout<<char(a)<<" ";
             }
             a++;
             cout<<endl;
          }
          int b=a+c;
          if(i>n/2+1)
          {
          	for(int j=n;j>=i;j--)
            {
               cout<<char(b)<<" ";
            }
            c++;
            cout<<endl;
          }
       }
       getch();
    }
    <pre/>
    #906 Reply

    Voeurn Sothavith

    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    int n;
    cout<< “N: “;cin>>n;
    for(int i=1;i<=n/2+1;i++)
    {
    for(int j=1;j<=i;j++)cout<<(char)(64+i);
    cout<< endl;
    }
    for(int i=1;i<=n/2;i++)
    {
    for(int j=n/2;j>=i;j-=1)cout<<(char)(101+i);
    cout<< endl;
    }
    getch();
    }
    //Vith

    #907 Reply

    Voeurn Sothavith

    //My previous answer is incorrect!
    #include<iostream.h>
    #include<conio.h>
    int main()
    {
    int n;
    cout << “N: “;cin >>n;
    for(int i=1;i<=n/2+1;i++)
    {
    for(int j=1;j<=i;j++)cout << (char)(64+i);
    cout << endl;
    }
    int g=n/2;
    for(int i=1;i<=n/2;i++)
    {
    for(int j=n/2;j>=i;j–)cout << (char)(98+g);
    g++;
    cout << endl;
    }
    getch();
    }

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Display Character
Your information: