C语言:输入年月日判定为当年的第几天
#include<stdio.h> main() { int year,month,date,x=0,t=0; printf("请输入年份:"); scanf("%d",&year); printf("请输入月份:"); scanf("%d",&month); printf("请输入几号:"); scanf("%d",&date); printf("\n"); month=month-1; if((year%4==0&&year%100==1)||year%400==0) t=1; switch (month) { case 11: x=x+30; case 10: x=x+31; case 9: x=x+30; case 8: x=x+31; case 7: x=x+31; case 6: x=x+30; case 5: x=x+31; case 4: x=x+30; case 3: x=x+31; case 2: x=x+29; case 1: x=x+31; } if (t==0 && month>1) x=x-1; x=x+date; printf("为本年的第%d天",x); }
#include <stdio.h> main() { int year,month,two,day,sum=0;//two代表2月 printf("请输入年份:"); scanf("%d",&year); printf("请输入月份:"); scanf("%d",&month); switch(month) { case 1:sum=0;break; case 2:sum=31;break; case 3:sum=59;break; case 4:sum=90;break; case 5:sum=120;break; case 6:sum=151;break; case 7:sum=181;break; case 8:sum=212;break; case 9:sum=243;break; case 10:sum=273;break; case 11:sum=304;break; case 12:sum=334;break; default:printf("输入错误"); } printf("请输入日:"); scanf("%d",&day); sum=sum+day; if(year%4==0&&year%100!=0||year%400==0&&month>2) sum++; printf("今天是%d年的第%d天\n",year,sum); }