Hi
I'm new to c programming and need some help with this code
I'm ask to write a program that reads in the side of a square and the prints that square out of asterisks. The program should work for squares of all side sizes between 1 and 20. For example, if the program reads a size of 4, it should print
Code:
****
****
****
****
It then ask me to modify the program so that it prints a hollow square. For example if the program reads a size of 5, it should print
Code:
*****
* *
* *
* *
*****
I was able to do the first part but don't know how to do the second part can any one help me
below is the code for the first part:
Code:
#include <stdio.h>
#include <stdlib.h>
int inputInteger(int, int);
#define MININPUT 1
#define MAXINPUT 20
#define TRUE 1
#define FALSE 0
int main (void)
{
int squareSize, column, row;
squareSize = inputInteger(MININPUT, MAXINPUT);
row = squareSize;
while(row >= 1){
column = 1;
while(column <= squareSize){
printf("*");
column++;
}
printf("\n");
row--;
}
system("pause");
}
int inputInteger(int minInput,int maxInput){
int reading;
int validInput;
do{
printf("\nPlease enter the number of side of a square: ");
fflush(stdin);
validInput = scanf("%d", &reading);
if(!validInput)
printf("\nThis is not a valid entry\n");
if((validInput == TRUE)&&((reading >maxInput)||(reading < minInput))){
printf("Error, the number entered needs to be between %d to %d\n", minInput, maxInput);
validInput = FALSE;
}
}while(!validInput);
return reading;
}