In this article, we are going to learn 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
Print square Pattern of Upper & Lower Case character in C
#include<stdio.h>
int main()
{
int num;
printf("Please enter the size of Square Box: ");
scanf("%d", &num);
for(int row=1; row<=num; row++)
{
for(int col=1; col<=num; col++)
{
if(row%2==0)
printf("%3c", row+64);
else
printf("%3c", row+96);
}
printf("\n");
}
return 0;
}
Output
Please enter the size of Square Box: 5
a a a a a
B B B B B
c c c c c
D D D D D
e e e e e