定义一个结构体变量,编写一个函数days,将主函数当中的年月日传到days中,计算之后用主函数输出。
1条回答 默认 最新
- qq_56915100 2022-05-07 17:09关注
#include
using namespace std;
struct date
{
int year;
int month;
int day;
};
date a;
int leapyear(int x);
int calculate(struct x);int leapyear(int x)//判断是否为闰年
{
if (((x & 4 == 0) && (x & 100 != 0) )||( x & 400 == 0))
return 1;
else
return 0;
}
int calculate(date a)//计算一年中的第几天
{
int sum = 0;
int b[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int i;
for (i = 0; i < a.month; i++)
sum = sum + b[i];
if (a.month > 2)
sum = sum + a.day + leapyear(a.year);
else
sum = sum + a.day;
return sum;
}
int main()
{
struct date a;
cout << "请输入年月日" << endl;
cin >> a.year >> a.month >> a.day;
int x;
x = calculate(a);
cout << "该日是一年中的第" << x << "天" << endl;
return 0;
}
解决 无用评论 打赏 举报
悬赏问题
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料