Solution ::
#include <stdio.h>
int main () //Monday-0
{ //Tuesday-1
int c=0,m=1,i,y,p; //Wednesday-2
printf("Enter a year: "); //Thursday-3
scanf("%d",&y); //Friday-4
for(i=1991;i<=y;i++) //Saturday-5
{ //Sunday-6
if((i%4)==0&&(i%100)!=0||(i%400)==0) //After 7 days,c = 0;(Monday, 1 week)
{ //If a year leap year, next year c=c+2
c++; //if(c==0) ; c = 0 ; Monday
p=i; //if(c==8) ; c = 1 ; Tuesday
} //c===day
else if((i-1)==p)
c=c+2;
else
c++;
if(c==7)
c=0;
else if(c==8)
c=1;
}
if(c==0)
printf("MONDAY");
else if (c==1)
printf("TUESDAY");
else if (c==2)
printf("WEDNESDAY");
else if (c==3)
printf("THURSDAY");
else if (c==4)
printf("FRIDAY");
else if (c==5)
printf("SATURDAY");
else if (c==6)
printf("SUNDAY");
return 0;
}
No comments:
Post a Comment