View Code of Problem 81

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

int a_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int b_month[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};

int main()
{
    int y,m,d;
    int sum=0,i;
    scanf("%d %d %d",&y,&m,&d);
    if(y%4==0&&y%100!=0 || y%400==0){//闰年
        for(i=1;i<m;i++){
            sum+=b_month[i];
        }
        sum+=d;
    }else{
        for(i=1;i<m;i++){
            sum+=a_month[i];
        }
        sum+=d;
    }
    printf("%d",sum);
	return 0;
}

Double click to view unformatted code.


Back to problem 81