本月有几天

来源:互联网 发布:mac jdk 默认安装路径 编辑:程序博客网 时间:2024/05/02 04:47
#include<iostream>using namespace std;int main(){int year,month;cout<<"输入年、月:"<<endl;cin>>year>>month;if(year%4==0 && year%400==0){switch(month){case 1:cout<<"本月有31天"<<endl;    break;case 2:cout<<"本月有29天"<<endl;break;case 3:cout<<"本月有31天"<<endl;    break;case 4:cout<<"本月有30天"<<endl;    break;case 5:cout<<"本月有31天"<<endl;    break;case 6:cout<<"本月有30天"<<endl;    break;case 7:case 8:cout<<"本月有31天"<<endl;    break;case 9:cout<<"本月有30天"<<endl;    break;case 10:cout<<"本月有31天"<<endl;    break;case 11:cout<<"本月有30天"<<endl;    break;case 12:cout<<"本月有31天"<<endl;    break;}}else{switch(month){case 1:cout<<"本月有31天"<<endl;    break;case 2:cout<<"本月有28天"<<endl;break;case 3:cout<<"本月有31天"<<endl;    break;case 4:cout<<"本月有30天"<<endl;    break;case 5:cout<<"本月有31天"<<endl;    break;case 6:cout<<"本月有30天"<<endl;    break;case 7:case 8:cout<<"本月有31天"<<endl;    break;case 9:cout<<"本月有30天"<<endl;    break;case 10:cout<<"本月有31天"<<endl;    break;case 11:cout<<"本月有30天"<<endl;    break;case 12:cout<<"本月有31天"<<endl;    break;}}return 0;}


#include<iostream>using namespace std;int main(){int year,month,days;cout<<"输入年、月:"<<endl;cin>>year>>month;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;case 2:if(year%4==0 && year%400==0)days=29;elsedays=28;break;}cout<<"本月有:"<<days<<"天"<<endl;return 0;}


心得体会:与老师的思路相比,我的还太显稚嫩。借鉴、学习、会越来越好的~

原创粉丝点击