C++: #CoolCodez Part 2

Situation: Making a right angle triangle of numbers and alphabets.

1
A     B
1      2      3
A      B     C     D
1       2     3     4     5

#include<iostream.h>
#include<conio.h>
void main()
{
      clrscr();
      int counter, sym, rows=1;
      char alpha;

      for (counter=5; counter>=rows; counter--)
      {
             cout<<"\n";
             alpha='A';
          
             for(sym=1; sym<=counter; sym++)
             {
                  if (counter%2==0)
                  {
                        cout<<" "<<sym<<" ";
                  }
                  else
                  {
                        cout<<" "<<alpha<<" ";
                        alpha++;
                  }
              }
       }
       getch();
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s