有多少天"/>
本月有多少天
上机内容:编写程序计算某年某月多少天
上机目的:练习使用switch
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者: 徐本锡
* 完成日期:2012 年 10 月27 日
* 版 本 号:v1.0
*
* 输入描述:输入 年 月
* 问题描述:无
* 程序输出:年 月 多少天
* 算法设计:无
程序代码:
#include <iostream> using namespace std; int main() {int year,month,days;cout<<"请输入 年 月"<<endl;cin>>year>>month;if(month==2){if(year%4==0&&year%100!=0 ||year%400==0)days=29;elsedays=28;}else{switch (month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:days=31;break;case 4:case 6:case 9:case 11:days=30;break;}}cout<<year<<"年 "<<month<<"月 "<<"有 "<<days<<"天"<<endl;return 0; }
结果(截屏):
我的总结:
ok!!!
更多推荐
本月有多少天
发布评论