Square
squareHollow() draws a hollow square and it takes 2 parameters:
noOfLines takes the number of lines.
ch takes the character to be displayed in the hollow square.
squareFilled() draws a filled square and it takes 2 parameters:
noOfLines takes the number of lines.
ch takes the character to be displayed in the filled square.
Code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"
using namespace std;
void squareHollow(int noOfLines,char ch)
{
for(int i=0;i<noOfLines;i++)
cout<<ch<<" ";
cout<<endl;
for(int k=0;k<noOfLines-2;k++)
{
for(int a=0;a<1;a++)
cout<<ch;
for(int b=0;b<noOfLines-2;b++)
cout<<" "<<" ";
for(int c=0;c<1;c++)
cout<<" "<<ch;
cout<<endl;
}
for(int i=0;i<noOfLines;i++)
cout<<ch<<" ";
cout<<endl;
}
void squareFilled(int noOfLines,char ch)
{
for(int i=0;i<noOfLines;i++)
cout<<ch<<" ";
cout<<endl;
for(int k=0;k<noOfLines-2;k++)
{
for(int a=0;a<1;a++)
cout<<ch;
for(int b=0;b<noOfLines-2;b++)
cout<<" "<<ch;
for(int c=0;c<1;c++)
cout<<" "<<ch;
cout<<endl;
}
for(int i=0;i<noOfLines;i++)
cout<<ch<<" ";
cout<<endl;
}
int main()
{
squareHollow(10,'*');cout<<endl;
squareFilled(10,'*');cout<<endl;
_getche();
return 0;
}
Output
* * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
0 comments:
Post a Comment