\(\begin{array}{ccccccc}&&*&*&*&&\\&&*&*&*&&\\*&*&*&*&*&*&*\\*&*&*&*&*&*&*\\*&*&*&*&*&*&*\\&&*&*&*&&\\&&*&*&*&&\end{array}\) 

Write a program that reads 2 odd numbers (1 for the length and 1 for the width) and displays the above pattern. (length =7 and width =3)


Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>

void main()
{
	int N, i, j, W;
	do{
		printf("Enter N: ");
		scanf("%d",&N);
	}while(N<=0 || N%2==0);

	do{
		printf("Enter W: ");
		scanf("%d",&W);
	}while(W<=0 || W%2==0);

	for (i=0 ; i<N ;i++)
	{
		for (j=0 ; j<N;j++) 
			if (((N/2-W/2)<= i && i<=(N/2+W/2))
				||
			((N/2-W/2)<= j && j<=(N/2+W/2)))
				printf("X");
 			else 
				printf(" ");	
		printf("\n");
	}

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Merging two binary search trees