Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int number;
- cin >> number;
- switch (number) {
- case 1:
- cout << "Monday" << endl;
- break;
- case 2:
- cout << "Tuesday" << endl;
- break;
- case 3:
- cout << "Wednesday" << endl;
- break;
- case 4:
- cout << "Thursday" << endl;
- break;
- case 5:
- cout << "Friday" << endl;
- break;
- case 6:
- cout << "Saturday" << endl;
- break;
- case 7:
- cout << "Sunday" << endl;
- break;
- default:
- cout << "Error" << endl;
- break;
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int number;
- cin >> number;
- string dayOfWeek =
- number == 1 ? "Monday" :
- number == 2 ? "Tuesday" :
- number == 3 ? "Wednesday" :
- number == 4 ? "Thursday" :
- number == 5 ? "Friday" :
- number == 6 ? "Saturday" :
- number == 7 ? "Sunday" : "Error";
- cout << dayOfWeek << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement