解题思路:1月到12月没什么规律,所以用个数组来累加,累加玩后在month>=3月开始判断是闰年与否,是的话sum++
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
int Judge(int year)
{
int a;
a=(year%100==0)?((year%400==0)?1:0):((year%4==0)?1:0);
return a;
}
int calculate(int year,int month,int day)
{
int i,n,x,sum=0,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for(i=0;i<month-1;i++)
{
sum+=a[i];
}
sum+=day;
if (month>=3)
{
if(Judge(year)==1)
sum++;
}
return sum;
}
typedef struct DATE
{
int year;
int month;
int day;
}Date;
int main()
{
int DAYS;
Date *p;
p=(Date *)malloc(sizeof(Date));
scanf("%d %d %d",&p->year,&p->month,&p->day);
DAYS=calculate(p->year,p->month,p->day);
printf("%d",DAYS);
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:1081 |
本人酷爱递归实现很多问题,这里也是浏览:592 |
简单的a+b (C语言代码)浏览:669 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:264 |
DNA (C语言描述,蓝桥杯)浏览:1645 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:385 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:512 |
DNA (C语言代码)浏览:434 |
剪刀石头布 (C语言代码)浏览:1507 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:576 |