0% found this document useful (0 votes)
17 views6 pages

Assignment Sir Amir

Uploaded by

TEKASHi K90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Assignment Sir Amir

Uploaded by

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

1.

Write a program using C++ to implement the given shape


below using loops of your choice.
*
* *
* * *
* * @ @
* * * * *

#include <iostream>
using namespace std;

int main() {
int rows = 5; // Number of rows in the shape

// Outer loop for rows


for (int i = 0; i < rows; i++)
{
// Inner loop for spaces before the stars
for (int j = 0; j < 2 * (rows - i - 1); j++) {
cout << " "; // Two spaces for alignment
}

// Inner loop for left stars


for (int k = 0; k <= i; k++) {
if (i == 3 && (k == i - 1 || k == i))
{
// 4th row and 2nd last and last positions (index starts from 0)
cout << "@ ";
} else {
cout << "* ";
}
}

cout << endl;

return 0;
}
OUTPUT
2 Write a program using C++ to implement the given shape
below using loops of your choice. Take the screen shot when
program runs successfully and shows the same output as
given below.
*
# #
& & &

#include <iostream>
using namespace std;

int main() {
int rows = 3;

for(int i = 1; i <= rows; ++i) {


for(int j = 1; j <= i; ++j) {
if(i == 1) {
cout << "* ";
} else if(i == 2) {
if(j == 1) {
cout << "# ";
} else {
cout << "# ";
}
} else {
cout << "& ";
}
}
cout << "\n";
}

return 0;
}

OUTPUT

You might also like