Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
556 B
1
Indexable
Never
int isWeekend(struct date date) {
    int year = date.year;
    int month = date.month;
    int day = date.day;

    if (month < 3) {
        month += 12;
        year -= 1;
    }
    
    // Zeller's Congruence algorithm to calculate the day of the week
    int h = (day + ((13 * (month + 1)) / 5) + year + (year / 4) - (year / 100) + (year / 400)) % 7;
    
    // 0 corresponds to Saturday and 1 to Sunday in Zeller's Congruence
    // So, if the result is 0 or 1, it's a weekend
    if (h == 0 || h == 1)
        return 1;
    else
        return 0;
}
Leave a Comment