0% found this document useful (0 votes)
11 views4 pages

Question2 PF2023

PF '23 Question
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Question2 PF2023

PF '23 Question
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

using namespace std;

int main()
{
int n, count1 = 0, count2 = 0, count3 = 2;

cout << "Enter n: ";


cin >> n;

while (n < 1)
{
cout << "Invalid input, the value must be positive, please enter it again:
";
cin >> n;
}

while (count1 < (2 * n - 1))


{
if (count1 < n)
{
count2 = 0;

while (count2 <= count1)


{
cout << "*";

count2++;
}

count2 = n * 2 - count3;

while (count2 != 0)
{
cout << " ";

count2--;
}

count2 = 0;

while (count2 <= count1)


{
cout << "*";

count2++;
}

cout << endl;


}
else
{
if (count1 == n)
count3 = 2;

count2 = 2 * n - count1 - 1;

while (count2 > 0)


{
cout << "*";

count2--;
}

count2 = 0;

while (count2 < count3)


{
cout << " ";

count2++;
}

count2 = 0;

count2 = 2 * n - count1 - 1;

while (count2 > 0)


{
cout << "*";

count2--;
}

cout << endl;


}

count1++;
count3 += 2;
}

cout << endl;

count1 = 0;
count2 = 0;

while (count1 < (2 * n) - 1)


{
if (count1 < n - 1)
{
cout << '*';

count2 = 0;

while (count2 < n - 2)


{
cout << " ";

count2++;
}

cout << " ";

if (count1 == 0)
{
count2 = 0;

while (count2 < n)


{
cout << "* ";

count2++;
}
}
else
{
cout << '*';
}

cout << endl;


}
else if (count1 == n - 1)
{
count2 = 0;

while (count2 < (2 * n) - 1)


{
cout << "* ";

count2++;
}

cout << endl;


}
else
{
count2 = 0;

while (count2 < n - 1)


{
if (count1 == (2 * n) - 2)
{
cout << "* ";
}
else
{
cout << " ";
}

count2++;
}

cout << '*';

count2 = 0;

while (count2 < n - 2)


{
cout << " ";

count2++;
}

cout << " ";

cout << '*';


cout << endl;
}

count1++;
}
}

You might also like