一、问题以及代码
/*
* 文件名称: ts.cpp
* 作 者:李甜甜
* 完成日期: 2017 年 4月 05日
* 版本号:v6.0
* 对任务及求解方法的描述部分:
* 输入描述: 无
* 问题描述:年份year月份monnt
* 程序输出:本月有几天
* 问题分析: 无
* 算法设计:
#include<iostream>
using namespace std;
int main()
{
int year,month;
cout<<"请输入年份和月份:";
cin>>year;
cin>>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)
cout<<"本月有31天"<<endl;
else if(month==4||month==6||month==9||month==11)
cout<<"本月有30天"<<endl;
else if(month==2)
cout<<"本月有29天"<<endl;
}
else
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
cout<<"本月有31天"<<endl;
else if(month==4||month==6||month==9||month==11)
cout<<"本月有30天"<<endl;
else if(month==2)
cout<<"本月有28天"<<endl;
}
return 0;
}
二,运行结果
<

通过本次C++实验,深入理解了如何利用运算符&&, ||, !来解决问题,掌握了计算本月有多少天的技能。"
133495240,19694693,编程技巧:绕过Windows设置中的Microsoft帐户,"['windows', 'microsoft', '编程']
最低0.47元/天 解锁文章

739

被折叠的 条评论
为什么被折叠?



