C Online Compiler
Example: C Program to print Hollow Square Star Pattern with Diagonal using loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to print Hollow Square Star Pattern with Diagonal using loop #include <stdio.h> int main() { int x = 0, y = 0; unsigned int sS = 0; printf("-----Enter the side of a square-----\n"); scanf("%u", &sS); printf("\n"); for (x = 1; x <= sS; ++x) { for (y = 1; y <= sS; ++y) { // It will check boundary conditions // It will check diagonal and secondary diagonal conditions if ((x == 1) || (x == sS) || (y == 1) || (y == sS) || (x == y) || (y == (sS - x + 1))) printf("*"); else printf(" "); } // It will print the new line printf("\n"); } return 0; }
12
Output
Clear
ADVERTISEMENTS