+ 1
What can be the code of this pattern?
Pattern : * * * * * * * * * * * * * * * *
2 Answers
0
//Here you go
#include<iostream>
using namespace std;
int main()
{
char ch = ' ';
int n = 6;
for(int i = 0; i <= n; i++)
{
for(int j= 0; j <= n*2; j++)
{
if(j < n)
{
if ( j <= n-i )
{
std::cout<<ch;
}
else
{
std::cout<<"*";
}
}
else
{
if ( j >= n+i )
{
std::cout<<ch;
}
else
{
std::cout<<'*';
}
}
}
std::cout<<endl;
}
for(int i = 0; i <= n; i++)
{
for(int j= 0; j <= n*2; j++)
{
if(j < n)
{
if ( j <= i )
{
std::cout<<ch;
}
else
{
std::cout<<"*";
}
}
else
{
if ( j >= (n+(n-i)))
{
std::cout<<ch;
}
else
{
std::cout<<'*';
}
}
}
std::cout<<endl;
}
}