How to write a C Program Side Length in C Programming Language ?
Solution For C Program :
#include <stdio.h>
#include <string.h>
void printChar(char c, int amount)
{
int i;
for (i = 0; i < amount; i++)
{
printf("%c", c);
}
}
void printSquare(char c, unsigned sideLength, char hollow)
{
int i;
if (hollow == 'y')
{
printChar(c, sideLength);
printf("\n");
for (i = 0; i < sideLength - 2; i++)
{
printChar(c, 1);
printChar(' ', sideLength - 2);
printChar(c, 1);
printf("\n");
}
printChar(c, sideLength);
printf("\n");
}
else
{
for (i = 0; i < sideLength; i++)
{
printChar(c, sideLength);
printf("\n");
}
}
return;
}
int main()
{
char print, hollow;
unsigned sideLength;
printf("Side length: ");
scanf("%u", &sideLength);
printf("Printed character: ");
scanf("%s", &print);
printf("Hollow (y/n): ");
scanf("%s", &hollow);
printSquare(print, sideLength, hollow);
return 0;
}