c语言中任意输入任一年份,计算这年到2021年1月1日,共经历了多少天,如2019年1月1日到2021年1月1日一共经历多少天。
计算有多少个闰年,就用365*年数加上闰年数
你题目的解答代码如下:
#include <stdio.h>
int main()
{
int n,y,s=0;
scanf("%d",&n);
for(y = n; y < 2021; y++)
{
if((y%4==0 && y%100!=0) || y%400==0)
s+=366;
else
s+=365;
}
printf("%d",s);
return 0;
}
如有帮助,望采纳!谢谢!