转换公历至农历的一段小程序,尚需要进一步验证测试再测试<代码见6楼>
话说204.2除以29.5等于6余27.2 这用c代码咋写啊
换句话说 已知204.2 29.5 如何能够求出来27.2 进而获取27 这才是最终目标
[ 本帖最后由 wp231957 于 2012-12-8 21:44 编辑 ]
#include<stdio.h> #define init_year 1977 int year_sumday(int year,int month,int day) { int sum=0; int rui[12]={31,29,31,30,31,30,31,31,30,31,30,31}; int ping[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int ruiflag=0; if((year%4==0 &&year%100!=0) || year%400==0) ruiflag=1; for(int index=0;index<month-1;index++) { if(ruiflag==1) sum+=rui[index];else sum+=ping[index]; } sum+=day; return sum; } int main() { int day,month,year,sum=0; int q,r; int yldate,yldate2; printf("\nplease input year,month,day\n"); scanf("%d %d %d",&year,&month,&day); sum=year_sumday(year,month,day); q=(year-init_year)/4; r=(year-init_year)%4; yldate2=(int)((14*q+10.6*(r+1)+sum)/29.5); yldate=(int)(14*q+10.6*(r+1)+sum-29.5*yldate2); printf("it is the %d th day.\n",yldate); return 0; }