View Code of Problem 81

#include <stdio.h>

int main(int argc, const char * argv[]) {
    int sum = 0;
    int i;
    int year, month, day;
    year = month = day = 0;
    int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    scanf("%d %d %d", &year, &month, &day);
   
    for(i = 0; i < month - 1; i++) {
        sum += days[i];
    }
    sum += day;
    
    if(year % 4 == 0) {
        if((year % 100 == 0 && year % 400 == 0) && (month >= 3)) {
            sum += 1;
        }
    }
    
    printf("%d\n", sum);
    return 0;
}

Double click to view unformatted code.


Back to problem 81