0% found this document useful (0 votes)
2 views2 pages

Oct 11

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

Oct 11

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

Question 2:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string a, b;
cout << "Enter a string: \n";
cin >> a;
for(int i = a.length() - 1; i >= 0; --i)
{
b += a[i];
}
cout << b << "\n";
if (a == b)
cout << "Thí is a palindrome";
else
cout << "It is not a palindrome";
return 0;
}

Question 3:
Letter A:
#include <iostream>
using namespace std;

int main() { //Letter A


int height = 7;
for (int i = 0; i < height; i++) { // Loop vertical
for (int j = 0; j <= 2 * height; j++) { //Loop horizontal
// First line
if (i == 0 && j == height) {
cout << "*";
}
// The slant
else if (i > 0 && (j == height - i || j == height + i)) {
cout << "*";
}
// Middle part
else if (i == height / 2 && j > height - i && j < height +
i) {
cout << "*";
}
// Gaps
else {
cout << " ";
}
}
cout << endl;
}
return 0;
}

Letter B:
#include <iostream>
using namespace std;

int main() {
int height = 7;
for (int i = 0; i < height; i++) {
for (int j = 0; j < height; j++) {
// The left side of B
if (j == 0) {
cout << "*";
}
// Middle lines (there’s 3 of them)
else if ((i == 0 || i == height / 2 || i == height - 1) &&
j < height - 1) {
cout << "*";
}
// The curves
else if ((i > 0 && i < height / 2 && j == height - 1) ||
(i > height / 2 && i < height - 1 && j == height
- 1)) {
cout << "*";
}
// Gaps
else {
cout << " ";
}
}
cout << endl; //
}
return 0;
}

You might also like