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