题目:
假设人的心率为每分钟跳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 m,n,a=0,b;
long c;
printf("Input your birth year:");
scanf("%d",&n);
printf("Input this year:");
scanf("%d",&m);
b=n;
for ( ;b<=m;b++)
{
if ((b%4==0&&b%100!=0)||(b%400==0))
{
a++;
}
}
if (((n%4==0&&n%100!=0)||(n%400==0))&&((m%4==0&&m%100!=0)||(m%400==0)))
{
c=365*24*60*75*(m-n)+1*(a-1)*24*60*75;
}
else
c=365*24*60*75*(m-n)+1*a*24*60*75;
printf("The heart beats in your life: %lu",c);
return 0;
}
其实我不太懂这个机制但这样过了。
生日到底是在2月29之前还是之后啊瘫