【发布时间】:2014-11-27 17:44:49
【问题描述】:
这是我当前的代码,输出如下:
请输入一个大于 2299160 的儒略日数
2299161
15 10 1582
但是,如果有小数点 2299161.1 等,这并不能提供确切的时间。
这将如何在 C 中实现?我已经知道数学了:
0.1 days = 0.1 * 24 hours = 2 hours (remainder 0.4 hours),
0.4 * 60 minutes = 24 minutes (remainder 0.0 seconds)
0.0 * 60 seconds = 0 seconds
#include <stdio.h>
int main( ) {
double jdn; /* you will need to store the user's input here... */
long lc, kc, nc, ic, jc;
int day, month, year;
printf("Please Enter a Julian Day number greater than 2299160 \n");
scanf("%lf",&jdn);
if( jdn > 2299160 ){
printf("%d\n",jdn);
lc = jdn + 68569;
nc = ((4 * lc) / 146097);
lc = lc - ((146097 * nc + 3) / 4);
ic = ((4000 * (lc + 1)) / 1461001);
lc = lc - ((1461 * ic) / 4) + 31;
jc = ((80 * lc) / 2447);
day = lc - ((2447 * jc) / 80);
lc = (jc / 11);
month = jc + 2 - 12 * lc;
year = 100 * (nc - 49) + ic + lc;
printf("%d %d %d\n", day, month, year);
}
else {
printf("Invalid number");
}
return 0;
}
【问题讨论】: