Determine Letter Case
Given a single character input, determine if its an uppercase letter. If so, print "yes"; otherwise, print "no".
#include <iostream>
using namespace std;
int main() {
char input;
cin >> input;
if (input >= 'A' && input <= 'Z') {
cout << "yes";
} else {
cout << "no";
}
return 0;
}
ASCII Sum or Numeric Value Calculation
Read two characters. If both are digits, output their numeric sum. Otherwise, output the sum of their ASCII values.
#include <iostream>
using namespace std;
int main() {
char first, second;
cin >> first >> second;
int ascii1 = static_cast<int>(first);
int ascii2 = static_cast<int>(second);
if (ascii1 >= 48 && ascii1 <= 57 && ascii2 >= 48 && ascii2 <= 57) {
cout << (ascii1 - 48) + (ascii2 - 48);
} else {
cout << ascii1 + ascii2;
}
return 0;
}
Print Lowercase Alphabet in Forward and Reverse Order
Display the lowercase English alphabet in forward order (first 13 letters), then next 13, followed by reverse order of last 13, then reverse of first 13, each line containing exactly 13 characters.
#include <iostream>
using namespace std;
int main() {
for (char c = 'a'; c <= 'm'; ++c) {
cout << c;
}
cout << '\n';
for (char c = 'n'; c <= 'z'; ++c) {
cout << c;
}
cout << '\n';
for (char c = 'z'; c >= 'n'; --c) {
cout << c;
}
cout << '\n';
for (char c = 'm'; c >= 'a'; --c) {
cout << c;
}
return 0;
}
Multiply Two Integers
Input two integers a and b, then output their product.
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a * b;
return 0;
}
Display ASCII Value of a Character
Read a character and output its corresponding ASCII value.
#include <iostream>
using namespace std;
int main() {
char ch;
cin >> ch;
cout << static_cast<int>(ch);
return 0;
}
Convert Case of a Character
Given a character, convert uppercase to lowercase and lowercase to uppercase. Leave non-letter characters unchanged.
#include <iostream>
using namespace std;
int main() {
char ch;
cin >> ch;
if (ch >= 'A' && ch <= 'Z') {
cout << static_cast<char>(ch + 32);
} else if (ch >= 'a' && ch <= 'z') {
cout << static_cast<char>(ch - 32);
} else {
cout << ch;
}
return 0;
}