Print the 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++)
{
star(i);
space(temp);
space(temp);
star(i);
cout<<endl;
temp--;
}
return 0;
}
Input
5
Output
* *
** **
*** ***
**** ****
**********
0 Comments