闰年相关的问题v4.0——计算心跳数
题目内容:
假设人的心率为每分钟跳75下,编程从键盘输入你的出生年和今年的年份,然后以年为单位计算并输出从你出生开始到目前为止的生命中已有的心跳总数(要求考虑闰年)。
程序运行结果示例1:
Input your birth year:1986↙
Input this year:2016↙
The heart beats in your life: 1183356000
输入提示信息:“Input your birth year:”
输入提示信息:“Input this year:”
输入格式:“%d”
输出格式:“The heart beats in your life: %lu”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
#include<stdio.h>
int main()
{
int year=0,this_year=0,sum=0;
printf("Input your birth year:");
scanf("%d",&year);
printf("Input this year:");
scanf("%d",&this_year);
/*因为如 现在是2023年 说明2023年还没过去,不需要=*/
for(int m=year;m<this_year;m++)
{
if(((m%4==0)&&(m%100!=0))||(m%400==0))
{
sum+=75 * 60 * 24 * 366;
}
else
{
sum+=75 * 60 * 24 * 365;
}
}
printf("The heart beats in your life: %lu",sum);
return 0;
}