diamond
unknown
c_cpp
3 years ago
773 B
9
Indexable
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
// from our calculation in khata we see there will
// be 2n-1 num of row (i) and 2n-1 num of columns (j)
for(int i = 0; i < (2*n-1); i++)
{
for(int j = 0; j < (2*n-1); j++)
{
//ternary operator below
if(i<n)
{
//also from calculation we see that * is present for the below limits when i<n
((j >= n-i-1) && (j <= n+i-1))? cout << "*": cout << " ";
}
else{
//and it is
((j >= i-n+1) && (j <= 2*n-i+2))? cout << "*": cout << " ";
}
}
cout << endl;
}
return 0;
}
Editor is loading...