Upper lower Case Mix Character Pattern in C++

In this article, we are going to learn Upper lower Case Mix Character Pattern in C++ a mixed pattern. This pattern is made of upper and lower case characters. Each odd row will print the lower case character and each even row will print the upper case characters. We will make use of the ASCII codes for upper case and lower case characters.

  • So for each even row, we will print the character by using “row+64” which will give us an Upper case character.
  • similarly, for each odd row, we will print the character by using “row+96” which will give us the lower case character.
Desired Output for Size 4:
a a a a
B B B B
c c c c
D D D D
#include <iostream>
using namespace std;
int main()
{
   int num;

   cout<<"Please enter the size of Square Box: ";
   cin>>num;

   for(int row=1; row<=num; row++)
   {
     for(int col=1; col<=num; col++)
     {
       if(row%2==0) 
		cout<< char(row+64);
       else 
		cout<< char(row+96);
     }
     cout<<"\n";
   }

   return 0;
}

Actual Output:

Please enter the size of Square Box: 5
aaaaa
BBBBB
ccccc
DDDDD
eeeee

We can mix the characters and numbers also in this pattern. So if we want to replace the upper case characters with numbers then we can just remove the ASCII value conversion.

#include <iostream>
using namespace std;
int main()
{
   int num;

   cout<<"Please enter the size of Square Box: ";
   cin>>num;

   for(int row=1; row<=num; row++)
   {
     for(int col=1; col<=num; col++)
     {
       if(row%2==0) 
		cout<< (row);
       else 
		cout<< char(row+96);
     }
     cout<<"\n";
   }

   return 0;
}

Output:

Please enter the size of Square Box: 5
aaaaa
22222
ccccc
44444
eeeee