day10(练习题)
1.根据月份判断季节
【描述】编写程序实现功能:输入一个代表月份的数字,根据输入的数字能够判断所属的季节,然后输出该季节。当输入的数字不是月份数字时,则输出“无效的月份”字样。
【输入描述】输入一个数字
【输出描述】输出该数字所属的季节
【样例输入】3
【样例输出】春季
#include <iostream>
using namespace std;int main()
{int month;cin >> month;//输入月份(1-12)if (month == 12 || month == 1 || month == 2){cout << "冬季";} else if (month >= 3 && month <= 5){cout << "春季";} else if (month >= 6 && month <= 8) {cout << "夏季";} else if (month >= 9 && month <= 11) {cout << "秋季";} else {cout << "无效的月份";}return 0;
}
2.字符判断
【描述】编写一个判断字符的程序,能够判断输入的字符类型属于大写字母、小写字母还是数字
当输入的都不是上述类型时,则输出“不是字母或数字”。
【输入描述】输入任意一个字符
【输出描述】输出该字符所属类型
【样例输入】A
【样例输出】‘A’ 是大写字母
#include <iostream>
using namespace std;int main() {char ch;cin >> ch;//输入一个字符if (ch >= 'A' && ch <= 'Z') {cout << "'" << ch << "' 是大写字母" << endl;} else if (ch >= 'a' && ch <= 'z') {cout << "'" << ch << "' 是小写字母" << endl;} else if (ch >= '0' && ch <= '9') {cout << "'" << ch << "' 是数字" <