#include<iostream>
using namespace std;
int a,b,c;
int sum( int a)
{
if(a%4==0||a%400==0)
cout<<"此年是闰年"<<endl;
else
cout<<"此年是平年"<<endl;
return a;
}
int sum1(int s,int d)
{
int x,z;
if(a%4==0||a%400==0)
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for(x=0;x<b-1;x++)
z=z+a[x];//这里有问题
if(a%4!=0||a%400!=0)
int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
for(x=0;x<b-1;x++)
z=z+a[x];//这里有问题
cout<<"今年到现在已经:"<<z<<endl;
return a ;
}
void main()
{
int x,y,z;
cout<<"输入年月日"<<endl;
cin>>a>>b>>c;
x=sum(a);
y=sum(a,b);//这里有问题,问题是函数参数调用太多。
}
给定某个年、月、日,计算出这一天为该年的的第几天。 要求:(1)用子函数实现闰年的判断 (2)用子函数实现日期的计算
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 五一编程 2021-12-19 16:10关注
#include <iostream> using namespace std; struct y_m_d { int year; int month; int day; }; int is_runnian(int iyear) { if((iyear%4==0&&iyear%100!=0)||(iyear%400==0)) return 1; else return 0; } int sday(int num,int iyear) { switch(num) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: if(is_runnian(iyear)) return 29; else return 28; } return 0; } int days(y_m_d date) { int i,s=0; for(i=1;i<=date.month;i++) s=s+sday(i,date.year); return s; } int main() { y_m_d date; int days(y_m_d); int day_sum; cin>>date.year>>date.month>>date.day; day_sum=days(date); cout<<day_sum<<endl; return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 nginx中的CORS策略应该如何配置
- ¥30 信号与系统实验:采样定理分析
- ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
- ¥20 Vite 打包的 Vue3 组件库,图标无法显示
- ¥15 php 同步电商平台多个店铺增量订单和订单状态
- ¥15 关于logstash转发日志时发生的部分内容丢失问题
- ¥17 pro*C预编译“闪回查询”报错SCN不能识别
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题