输入某年某月某日,判断这一天是这一年的第几天 用if函数C++怎么编程
1个回答
展开全部
#include<iostream>
using namespace std;
void main()
{
int a, b, c, d;
cout << "请输入年,月,日" << endl;
cin >> a >> b >> c;
d = 0;
switch (b)
{
case 12:d = d + c + 30;
case 11:d = d + c + 31;
case 10:d = d + c + 30;
case 9:d = d + c + 31;
case 8:d = d + c + 31;
case 7:d = d + c + 30;
case 6:d = d + c + 31;
case 5:d = d + c + 30;
case 4:d = d + c + 30;
case 3:
if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0))
d = d + c + 29;
else
d = d + c + 28;
case 2:d = d + c + 31;
case 1:d = d + c;
}
cout << "为这一年的第" << d << "天" << endl;
}
using namespace std;
void main()
{
int a, b, c, d;
cout << "请输入年,月,日" << endl;
cin >> a >> b >> c;
d = 0;
switch (b)
{
case 12:d = d + c + 30;
case 11:d = d + c + 31;
case 10:d = d + c + 30;
case 9:d = d + c + 31;
case 8:d = d + c + 31;
case 7:d = d + c + 30;
case 6:d = d + c + 31;
case 5:d = d + c + 30;
case 4:d = d + c + 30;
case 3:
if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0))
d = d + c + 29;
else
d = d + c + 28;
case 2:d = d + c + 31;
case 1:d = d + c;
}
cout << "为这一年的第" << d << "天" << endl;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询