输入某年,某月,某日,判断这一天是这一年的第几天。
#include"stdio.h" #include"conio.h" main( ) { int day|month|year|sum|leap; printf(" please input year|month|day "); scanf("%d|%d|%d"|&year|&month|&day); switch(month)/*先计算某月以前月份的总天数*/ { case1:sum=0;break; case2:sum=31;break; case3:sum=59;break; case4:sum=90;break; case5:sum=120;break; case6:sum=151;break; case7:sum=181;break; case8:sum=212;break; case9:sum=243;break; case10:sum=273;break; case11:sum=304;break; case12:sum=334;break; default:printf("data error");break; } sum=sum+day;/*再加上某天的天数*/ if(year%400==0||(year%4==0&&year%100!=0))/*判断是不是闰年*/ leap=1; else leap=0; if(leap==1&&month>2)/*如果是闰年且月份大于2,总天数应该加一天*/ sum++: printf("It is the %d th day."|sum); getch( ); }
免费的网站请分享给朋友吧