Write a function that displays at the left margin of the screen a solid square o
ID: 3625162 • Letter: W
Question
Write a function that displays at the left margin of the screen a solid square of anycharacter enter by user whose side is specified in integer parameter side.
Input: Take side value from user as input and the character for displaying solid rectangle. Suppose
user enter side value: 5 and display character ‘#’ then function should display following solid square.
#####
#####
#####
#####
#####
Write a main program which should input two values side and displaying character from user. Pass
these two values to the function and then function should display appropriate Solid Square.
Explanation / Answer
please rate - thanks
you didn't specify the language.
Here is C and C++
#include <stdio.h>
#include<conio.h>
void drawSquare(int,char);
int main()
{int n;
char c;
printf("Enter size of square: ");
scanf("%d",&n);
while (getchar()!= ' ');
printf("Enter character to use: ");
scanf("%c",&c);
drawSquare(n,c);
getch();
return 0;
}
void drawSquare(int n,char c)
{int i,j;
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
printf("%c",c);
printf(" ");
}
}
-----------------------------------------------------------
#include <iostream>
using namespace std;
void drawSquare(int,char);
int main()
{int n;
char c;
cout<<"Enter size of square: ";
cin>>n;
cout<<"Enter character to use: ";
cin>>c;
drawSquare(n,c);
system("pause");
return 0;
}
void drawSquare(int n,char c)
{int i,j;
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
cout<<c;
cout<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.