第九周项目4-输入年月,输出本月天数

来源:互联网 发布:淘宝联盟怎么注销 编辑:程序博客网 时间:2024/05/21 07:48
/*          *程序的版权和版本声明部分:          *Copyright(c)2013,烟台大学计算机学院学生          *All rights reserved.          *文件名称:          *作者:田成琳          *完成日期:2013年 10月15 日          *版本号:v1.0          *对任务及求解方法的描述部分:          *输入描述:输入年月,显示本月多少天 *问题描述:输入年月,显示本月多少天*程序输出:本月天数  *问题分析:          *算法设计: 先判断是否闰年         */    我的程序:#include<iostream>using namespace std;int main(){int year,month,day;cout<<"请输入年,月:"<<endl;cin>>year>>month;if(year%4==0&&year%100!=0||year%400==0)    //先讨论是不是闰年{if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)day=31;else if(month==4||month==6||month==9||month==11)day=30;elseday=29;            //闰年2月有29天}else{        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)     day=31;else if(month==4||month==6||month==9||month==11)     day=30;else              day=28;}cout<<"本月有"<<day<<"天"<<endl;return 0;} 

上机内容:练习
运行结果:
心得体会:在解决实际问题时,往往要经过讨论,灵活运用if-else语句。关键头脑中要先有此问题的算法,解法。

原创粉丝点击