Print the Pattern
*****
* *
* *
* *
*****
Code
#include<bits/stdc++.h>
using namespace std;
// Function to print star
void star(int y)
{
while(y--)
{
cout<<"*";
}
}
// Function to print spaces
void space(int x)
{
while(x>=0)
{
x--;
cout<<" ";
}
}
// main function
int main()
{
int n;
cin>>n;
star(n);
for(int i=0;i<n-2;i++)
{
cout<<"\n*";
space(n-3);
cout<<"*";
}
cout<<endl;
star(n);
return 0;
}
Input
5
Output
*****
* *
* *
* *
*****
0 Comments