This is the C Program.................... Calender.c ................... Run it and check it out... If there is any fault, then in4m..... Comments are welcome....
#include
#include
main()
{
int date, month, year, days, nyear;
int x,y,k,weeks,new, remainder;
int odd_days, total_odd_days,leap_odd_days,leapyear_odd_days;
printf("Enter date-month-year");
scanf("%d%d%d",&date,&month,&year);
nyear=year-1;
x=nyear%100;
new=nyear-x;
remainder=new%400;
if(remainder%400==0)
leap_odd_days=0;
if(remainder%400==100)
leap_odd_days=5;
if(remainder%400==200)
leap_odd_days=3;
if(remainder%400==300)
leap_odd_days=1;
y=x/4;
k=(y+x)%7;
leapyear_odd_days=k+leap_odd_days;
if(month==1)
days=date;
else if(month==2)
days=31+date;
else if(month==3)
{
if(year%4==0)
days=31+29+date;
else
days=31+28+date;
}
else if(month==4)
{
if(year%4==0)
days=31+29+31+date;
else
days=31+28+31+date;
}
else if(month==5)
{
if(year%4==0)
days=31+29+31+30+date;
else
days=31+28+31+30+date;
}
else if(month==6)
{
if(year%4==0)
days=31+29+31+30+31+date;
else
days=31+28+31+30+31+date;
}
else if(month==7)
{
if(year%4==0)
days=31+29+31+30+31+30+date;
else
days=31+28+31+30+31+30+date;
}
else if(month==8)
{
if(year%4==0)
days=31+29+31+30+31+30+31+date;
else
days=31+28+31+30+31+30+31+date;
}
else if(month==9)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+date;
else
days=31+28+31+30+31+30+31+31+date;
}
else if(month==10)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+30+date;
else
days=31+28+31+30+31+30+31+31+30+date;
}
else if(month==11)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+30+31+date;
else
days=31+28+31+30+31+30+31+31+30+31+date;
}
else if(month==12)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+30+31+30+date;
else
days=31+28+31+30+31+30+31+31+30+31+30+date;
}
weeks=days/7;
odd_days=days%7;
total_odd_days=leapyear_odd_days + odd_days;
if((total_odd_days % 7 )== 0)
printf("\nSUNDAY");
if((total_odd_days % 7 )== 1)
printf("\nMONDAY");
if((total_odd_days % 7 )== 2)
printf("\nTUESDAY");
if((total_odd_days % 7 )== 3)
printf("\nWEDNESDAY");
if((total_odd_days % 7 )== 4)
printf("\nTHURSDAY");
if((total_odd_days % 7 )== 5)
printf("\nFRIDAY");
if((total_odd_days % 7 )== 6)
printf("\nSATURDAY");
printf("\n");
}
#include
#include
main()
{
int date, month, year, days, nyear;
int x,y,k,weeks,new, remainder;
int odd_days, total_odd_days,leap_odd_days,leapyear_odd_days;
printf("Enter date-month-year");
scanf("%d%d%d",&date,&month,&year);
nyear=year-1;
x=nyear%100;
new=nyear-x;
remainder=new%400;
if(remainder%400==0)
leap_odd_days=0;
if(remainder%400==100)
leap_odd_days=5;
if(remainder%400==200)
leap_odd_days=3;
if(remainder%400==300)
leap_odd_days=1;
y=x/4;
k=(y+x)%7;
leapyear_odd_days=k+leap_odd_days;
if(month==1)
days=date;
else if(month==2)
days=31+date;
else if(month==3)
{
if(year%4==0)
days=31+29+date;
else
days=31+28+date;
}
else if(month==4)
{
if(year%4==0)
days=31+29+31+date;
else
days=31+28+31+date;
}
else if(month==5)
{
if(year%4==0)
days=31+29+31+30+date;
else
days=31+28+31+30+date;
}
else if(month==6)
{
if(year%4==0)
days=31+29+31+30+31+date;
else
days=31+28+31+30+31+date;
}
else if(month==7)
{
if(year%4==0)
days=31+29+31+30+31+30+date;
else
days=31+28+31+30+31+30+date;
}
else if(month==8)
{
if(year%4==0)
days=31+29+31+30+31+30+31+date;
else
days=31+28+31+30+31+30+31+date;
}
else if(month==9)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+date;
else
days=31+28+31+30+31+30+31+31+date;
}
else if(month==10)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+30+date;
else
days=31+28+31+30+31+30+31+31+30+date;
}
else if(month==11)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+30+31+date;
else
days=31+28+31+30+31+30+31+31+30+31+date;
}
else if(month==12)
{
if(year%4==0)
days=31+29+31+30+31+30+31+31+30+31+30+date;
else
days=31+28+31+30+31+30+31+31+30+31+30+date;
}
weeks=days/7;
odd_days=days%7;
total_odd_days=leapyear_odd_days + odd_days;
if((total_odd_days % 7 )== 0)
printf("\nSUNDAY");
if((total_odd_days % 7 )== 1)
printf("\nMONDAY");
if((total_odd_days % 7 )== 2)
printf("\nTUESDAY");
if((total_odd_days % 7 )== 3)
printf("\nWEDNESDAY");
if((total_odd_days % 7 )== 4)
printf("\nTHURSDAY");
if((total_odd_days % 7 )== 5)
printf("\nFRIDAY");
if((total_odd_days % 7 )== 6)
printf("\nSATURDAY");
printf("\n");
}
No comments:
Post a Comment