高斯日记

xiaoxiao2021-02-28  42

大数学家高斯有个好习惯:无论如何都要记日记。

他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210

后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?

高斯出生于:1777年4月30日。

在高斯发现的一个重要定理的日记上标注着:5343,因此可算出那天是:1791年12月15日。

高斯获得博士学位的那天日记上标着:8113

请你算出高斯获得博士学位的年月日。

代码:

#include <stdio.h> #include <stdlib.h> int a[2][12] = {{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; int isLeap(int n) //判断是否为闰年; { if(n@0==0 || (n%4==0 && n0!=0)) { return 1; }else { return 0; } } int nday(int y,int m,int d)//把月日期转换为天数; { int i,n=0; for(i=0;i<m-1;i++) { n+=a[isLeap(y)][i]; } n+=d; return n; } void ymd(int y,int days)//截止到年月日; { int i,ty,tm,temp; for(i=y;days>0;i++) { ty = i; tm = days; if(isLeap(i)) { days-=366; }else { days-=365; } } printf("%d--",ty); for(i=0;tm>0;i++) { ty = i; temp = tm; tm-=a[isLeap(ty)][i]; } printf("%d--%d",ty+1,temp); } int main(int argc, char *argv[]) { int n = 8113; int y = 1777,m = 4,d = 30; n = n-1+nday(1779,4,30); ymd(y,n); return 0; }
转载请注明原文地址: https://www.6miu.com/read-1700038.html

最新回复(0)