*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作者:李全港
* 完成日期:2012 年10月26日
* 版本号:v1.0
*
* 输入描述:输入年份月份
* 问题描述:学会使用switch语句
* 程序输出:输出本月有几天
程序:
#include <iostream>
using namespace std;
int main()
{ int year,month,days; cout<<"请输入年,月"<<"\n"; cin>>year>>month; switch(month) { case 1: case 3: case 5: case 7: case 9: case 11: days=31; break; case 4: case 6: case 8: case 10: case 12: days=30; break; case 2: if(year%4==0 && year%100!=0 || year%400==0) days=29; else days=28;} cout<<year<<"年"<<month<<"月有"<<days<<"天"<<"\n"; return 0;
}
心得体会:28,,29还没搞明白,有点懒了。