IN C++ PLEASE.
Write a program where the user enters a number and you output an unfilled square of stars. (DO NOT PROMPT THE USER, just take in a number, The only console output should be the squares). For example the program would start with console input,
The user would enters 3, you would output (note 3 is the lowest number your program will be tested with)
*** * * ***
or, The user enters 5, you would output
*****
* *
* *
* *
*****
or, The user enters 7, you would output
*******
* *
* *
* *
* *
*******
Program:
#include<iostream>
using namespace std;
int main()
{
int i,j,no;
cin>>no;
if(no>=3)
{
for(i=1;i<=no;i++)
{
if(i==1 || i==no)
{
for(j=1;j<=no;j++)
{
cout<<"* ";
}
}
else
{
for(j=1;j<=no;j++)
{
if(j==1 || j==no)
{
cout<<"* ";
}
else
{
cout<<" ";
}
}
}
cout<<endl;
}
}
else
{
cout<<"Input value has to be greater or equal to 3 i.e. 3 is
the lowest number!";
}
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.