In this tutorial, we will write a C program to print a square pattern of any characters. Before that, you may go through the following topics in C.
Square pattern of character in C
The program simply asks the user to enter the character that you want to print and the side of a square that is to be printed. And using that information inside a for loop, it prints the result.
#include <stdio.h>
int main()
{
int i, j, rows;
char ch;
printf("Enter the character you want to print: ");
scanf("%c", &ch);
printf("Enter the side of a Square: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= rows; j++)
printf("%c ", ch);
printf("\n");
}
return 0;
}
Output:
Enter the character you want to print: $
Enter the side of a Square: 5
$ $ $ $ $
$ $ $ $ $
$ $ $ $ $
$ $ $ $ $
$ $ $ $ $