You are on page 1of 4

COMPUTER PROGRAMMING ASSIGNMENT#1

Name : MUHAMMAD AWAIS KHAWAR

BCE-02
Enrollement:01-132232-022
Q1:
CODE:
#include <iostream>
using namespace std;
int main()
{ int rows = 10; int cols = rows - 1;
cout << endl;
for (int i = 1; i <= rows / 2; i++) {
for (int j = cols; j >= 1; j--) {
if ((j > cols - (rows / 2 - i)) || j <= rows / 2 - i)
{ cout << " ";
} else {
if ((i > 2 && i < rows / 2) && (j > rows / 2 && j < cols - (i - 1))) {
cout << " ";
} else {
if (j == cols - (rows / 2 - i) + 1 || j == cols + (rows / 2 - i) + 1) {
cout << "*";
} else {
cout << " ";
}
}
}
}
cout << endl;
}

return 0;
}
OUTPUT:
Q2:
CODE:

#include <iostream>
using namespace std;

int main()
{
int rows = 10; int col = rows - 1;
cout << endl;

// Upper triangle
for (int i = 1; i <= rows / 2; i++)
{ for (int j = col; j >= 1; j--) {
if ((j > col - (rows / 2 - i)) || j <= rows / 2 - i) {
cout << " ";
} else {
if ((i > 2 && i < rows / 2) && (j < col - (i - 1) && j > rows / 2) && (i %
2 != 0)) {
cout << " ";
} else if
((i > 2 && i < rows / 2) && (j <= col - (i - 2) && j > rows / 2) && (i % 2
== 0)) {
cout << " ";
} else {
cout << "*";
}
}
}
cout << endl;
}

// Lower shape
for (int i = 1; i <= (rows - rows / 2) - 1; i++)
{ for (int j = 1; j <= col; j++) {
if (j == rows / 2 || (j == col - i)) {
cout << "*";
} else {
cout << " ";
}
}
cout << endl;
}

return 0;
}
OUTPUT:

You might also like