用C语言计算给定年份中给定日期(如星期日、星期一等)的总数

用C语言计算给定年份中给定日期(如星期日、星期一等)的总数,c,calendar,C,Calendar,随着标题的清除,我想用c语言计算给定年份中1600-2500之间给定日期的总数。我已经写了一些代码,但在计算闰年天数方面有点结巴。请帮帮我 #include<stdio.h> #include<string.h> int calculateNoOfDays(int year,int choice); int isLeap(int year); int main() { int choice,year; int count; char d

随着标题的清除,我想用c语言计算给定年份中1600-2500之间给定日期的总数。我已经写了一些代码,但在计算闰年天数方面有点结巴。请帮帮我

#include<stdio.h>
#include<string.h>

int calculateNoOfDays(int year,int choice);
int isLeap(int year);

int main()
{
    int choice,year;    
    int count;
    char dayName[12];

     do{
         printf("Please Enter a year between 1601 and 2500\n");
         scanf("%d",&year);
     }
     while(!(year>=1601 && year<=2500));


 printf("Please select an option between 1 and 7: \nMonday: 1\nTuesday: 2\nWednesday: 3\nThursday: 4\nFriday: 5\nSaturday: 6\nSunday: 7\n");
        scanf("%d",&choice);


    switch((choice))
    {

            case 1:strcpy(dayName,"Monday");
    break;
        case 2:strcpy(dayName,"Tuesday");
    break;
    case 3:strcpy(dayName,"Wednesday");
    break;
    case 4:strcpy(dayName,"Thursday");
    break;
    case 5:strcpy(dayName,"Friday");
    break;
    case 6:strcpy(dayName,"Saturday");
    break;
    case 7:strcpy(dayName,"Sunday");
    break;

}

count=calculateNoOfDays(year,choice);
printf("For the given year, the number of %ss in that year is: %d \n",dayName,count);

return (1);
}
#包括
#包括
整数计算天数(整数年,整数选择);
国际年(国际年);
int main()
{
整数选择,年份;
整数计数;
char dayName[12];
做{
printf(“请输入介于1601和2500之间的年份\n”);
scanf(“%d”和“年”);
}
而(!(year>=1601&&year如您所知,很容易确定哪些年份是闰年。以下是伪代码:

if year is divisible by 400 then
   is_leap_year
else if year is divisible by 100 then
   not_leap_year
else if year is divisible by 4 then
   is_leap_year
else
   not_leap_year
这样你就得到了一年中的天数:365天或366天

下一步将是确定1月1日的工作日。这应该可以通过修改标准来实现。你可能需要做一些迭代来达到这一点,但如果你聪明的话,可能没有


然后剩下的是一个简单的计算来计算你的天数。

你的
calculateNoOfDays()
是什么样子的?另外,请注意,你应该
main
返回0
以表示成功。继续“唠叨”关于@Lstor编写的
main
,对于不带参数的函数,还应始终使参数
void
。否则在C中,函数被指定为带未知数量的未知参数。听起来像是project euler C中的问题:。使用mktime(3p)并在星期一和星期六进行迭代和测试sundays@Kira你肯定不需要每天都迭代(见我的答案)。可能需要一些迭代才能到达感兴趣的年份的1月1日,但在那之后,答案只不过是一次减法和一次除法(7)如果我输入2013并输入第1天,那么它应该计算2013年有多少个星期一