\(\begin{array}{ccccc}&&*&&\\&&*&&\\*&*&*&*&*\\&&*&&\\&&*&&\end{array}\)
Write a program that reads an odd number and displays the above pattern.
Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
void main()
{
int N, i, j;
do{
printf("Enter N: ");
scanf("%d",&N);
}while(N<=0 || N%2==0);
for (i=0 ; i<N ;i++)
{
for (j=0 ; j<N;j++)
if (i==N/2 || j==N/2)
printf("X");
else
printf(" ");
printf("\n");
}
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Display the addition sign of 2 integers without performing the sum