View Code of Problem 81

# include<stdio.h>
struct date{
  int year;
  int month;
  int day;
} Date;

int countDay(int A[],int month,int day){
	int days=0;
	for(int i=0;i<month-1;i++){
		days+=A[i];
	}
	days+=day;
	return days;
}
int main(){

	int R[]={31,29,31,30,31,30,31,31,30,31,30,31};
	int P[]={31,28,31,30,31,30,31,31,30,31,30,31};
	int days;
	scanf("%d %d %d",&Date.year,&Date.month,&Date.day);
	if(Date.year%4==0){
			
		if(Date.year%400==0){
		
		  days=countDay(R,Date.month,Date.day);
		}
		else if(Date.year%100==0){
		   days= countDay(P,Date.month,Date.day);
		}
		else{
		  days=	countDay(R,Date.month,Date.day);
		}
	}
	else{
	   days=countDay(P,Date.month,Date.day);
	}
	printf("%d",days);
	return 0;
}

Double click to view unformatted code.


Back to problem 81