Created
August 16, 2014 06:10
-
-
Save froghramar/c56d847d74a70ca1586d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
char *months[]={" ","\n\n\n\n\t\t January","\n\n\n\n\t\t February","\n\n\n\t\t March","\n\n\n\n\t\t April","\n\n\n\n\t\t May","\n\n\n\n\t\t June","\n\n\n\n\t\t July","\n\n\n\n\t\t August","\n\n\n\n\t\t September","\n\n\n\n\t\t October","\n\n\n\n\t\t November","\n\n\n\n\t\t December"}; | |
int dayinmonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; | |
int getdaycode(int year) | |
{ | |
int daycode,n; | |
n=year-1; | |
daycode=1 + (2 * 13) + ((3 * (13+1))/5) + n + (n/4) - (n/100) + (n/400) + 2; | |
daycode=(daycode%7)-1; | |
if(daycode<0) | |
{daycode=daycode+7;} | |
return daycode; | |
} | |
int getleapyear(int year) | |
{ | |
if((year%4==0 && year%100!=0)||year%400==0) | |
{dayinmonth[2]=29;} | |
else{dayinmonth[2]=28; } | |
return dayinmonth[2]; | |
} | |
void calendar(int year,int daycode) | |
{ | |
int month,day; | |
for(month=1;month<=12;month++) | |
{ | |
printf("\t\t%s\n\n\n",months[month]); | |
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n"); | |
for(day=1;day<=daycode;day++) | |
printf(" \t"); | |
for(day=1;day<=dayinmonth[month];day++) | |
{ | |
printf("%2d",day); | |
if((day+daycode)%7>0) | |
printf("\t"); | |
else{printf("\n");} | |
} | |
daycode=(daycode+dayinmonth[month])%7; | |
} | |
} | |
int main() | |
{ | |
int year,daycode; | |
printf("Enter year : "); | |
scanf("%d",&year); | |
daycode=getdaycode(year); | |
dayinmonth[2]=getleapyear(year); | |
calendar(year,daycode); | |
printf("\n"); | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment