以下是使用C语言编写的解决方案:

#include <stdio.h>

// 判断是否为闰年
int isLeapYear(int year) {
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
        return 1;
    }
    
    return 0;
}

// 计算星期几
int calculateWeekday(int year, int month, int day) {
    if (month == 1 || month == 2) {
        month += 12;
        year--;
    }
    
    int c = year / 100;
    int y = year % 100;
    
    int week = (c / 4 - 2 * c + y + y / 4 + 13 * (month + 1) / 5 + day - 1) % 7;
    
    if (week < 0) {
        week += 7;
    }
    
    return week;
}

int main() {
    int year = 1901;
    int month = 1;
    
    while (calculateWeekday(year, month, 1) != 0) {
        month++;
        if (month > 12) {
            month = 1;
            year++;
        }
    }
    
    printf('%d\n', month);
    
    return 0;
}

这个程序通过循环遍历年份和月份,使用calculateWeekday函数来计算每个月的第一天是星期几。当第一个星期日出现时,即计算得到的值为0时,输出当前的月份。

希望这个C程序能够帮助您找到1901年的第一个星期日所在的月份!

1901年第一个星期日是几月?C语言程序解答

原文地址: https://www.cveoy.top/t/topic/b2Dv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录