代码有问题,试试这样:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdarg.h>
int Days(int *a, int *b);
int Days(int *a, int *b){
unsigned int x = *a;
int y = *b;
int days;
switch(x){
case 1: days = y;break;
case 2: days = 31+y;break;
case 3: days = 31+28+y;break;
case 4: days = 31+28+31+y;break;
case 5: days = 31+28+31+30+y;break;
case 6: days = 31+28+31+30+31+y;break;
case 7: days = 31+28+31+30+31+30+y;break;
case 8: days = 31+28+31+30+31+30+31+y;break;
case 9: days = 31+28+31+30+31+30+31+31+y;break;
case 10: days = 31+28+31+30+31+30+31+31+30+y;break;
case 11: days = 31+28+31+30+31+30+31+31+30+31+y;break;
case 12: days = 31+28+31+30+31+30+31+31+30+31+30+y;break;
default: break;
}
return days;
}
int main(void)
{
int year, month, day;
int DAY;
printf("please enter year-month-day.eg: 1995-5-3");
scanf("%d-%d-%d",&year, &month, &day);
if(year%4 ==0 || year%400 == 0){
DAY = Days(&month, &day) + 1;
printf("this is the %d th day of %d", DAY, year);
}
else
printf("this is the %d th day of %d", Days(&month, &day), year);
return 0;
}
|