您的位置:首页 > 编程语言 > C语言/C++

C++第2次实验作业项目2:本月有几天

2017-03-13 21:25 239 查看
一、问题及代码

//*
//*文件名称:作业2.cpp
//*作 者;钟金勇
//*完成日期:2017年3月13日
//*版 本 号;
//*对任务及求解方法的描述部分:
//*输入描述:
//*问题描述;
//*程序输出:
//*问题分析:
//*算法设计:
//*
#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"请输入年份,请输入月份";
cin>>x>>y;
switch((y>=1)&&(y<=12))
{
case 1:cout<<x<<"年1月有31天。"<<endl;break;
case 2:
if((x%4==0&&x%100!=0)||(x%400==0))
{
cout<<x<<"年2月有29天。"<<endl;break;
}
else
cout<<x<<"年2月有28天。"<<endl;break;
case 3:cout<<x<<"年3月有31天。"<<endl;break;
case 4:cout<<x<<"年4月有30天。"<<endl;break;
case 5:cout<<x<<"年5月有31天。"<<endl;break;
case 6:cout<<x<<"年6月有30天。"<<endl;break;
case 7:cout<<x<<"年7月有31天。"<<endl;break;
case 8:cout<<x<<"年8月有31天。"<<endl;break;
case 9:cout<<x<<"年9月有30天。"<<endl;break;
case 10:cout<<x<<"年10月有31天。"<<endl;break;
case 11:cout<<x<<"年11月有30天。"<<endl;break;
case 12:cout<<x<<"年12月有31天。"<<endl;break;
}
cin.get();
return 0;
}


二、运行结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  编程 c语言