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