C++: #CoolCodez

Situation: Making patterns with numbers and alphabets.

Pattern 1:

1
1   2
1   2   3
1   2   3   4
1   2   3   4   5

#include 
#include 
void main()
{
    clrscr();
    int sym, counter, row=5;
   
    for (counter=1; counter<=rows; countner++)
    {
         for (sym=1; symb<=counter; sym++)
         {
              cout<<" "<<sym<<" ";
         }
         cout<<"\n";
    }

    getch();

}

1   2   3   4   5
1   2   3   4
1   2   3
1   2
1

Changes to the previous code have been highlighted:

#include  
#include 
void main() 
{ 
    clrscr(); 
    int sym, counter, row=5; 

    for (counter=rows; counter>=1; countner--) 
    { 
         for (sym=1; symb<=counter; sym++) 
         { 
                 cout<<" "<<sym<<" ";
         } 
    
         cout<<"\n";  
    } 
    getch();
 
}

Pattern 2:

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

#include  
#include  
void main() 
{ 
    clrscr(); 
    int sym, counter, row=5; 
    char alpha;

    for (counter=1; counter<=rows; countner++) 
    { 
         
         cout<<"\n";
         alpha='A';  
        
         for (sym=1; symb<=counter; sym++) 
         { 
              cout<<"\t"<<alpha;
              alpha++;   
         } 
    } 
    getch(); 

}

Pattern 3:

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

#include <iostream.h>
#include <conio.h>
void main() 
{ 
    clrscr(); 
    int sym, counter, row=5; 
    char alpha='A';

    for (counter=1; counter<=rows; countner++) 
    { 
         for (sym=1; symb<=counter; sym++) 
         { 
                   cout<<" "<<alpha<<" "; 
         } 
         alpha++;

         cout<<"\n"; 
     } 
     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