0% found this document useful (0 votes)
13 views1 page

Calendar

This is Calendar code for C.

Uploaded by

login.user.0070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Calendar

This is Calendar code for C.

Uploaded by

login.user.0070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int get_1st_weekday(int year)


{
int d;
d=(((year-1)*365)+((year-1)/4)-((year-1)/100)+((year)/400)+1)%7;
return d;
}
void main()
{
int
year,month,monthDay[]={31,28,31,30,31,30,31,31,30,31,30,31},day,days_in_month,weekd
ays=0,startingDay;
char
*months[]={"January","Febuary","March","April","May","June","July","August","Septem
ber","October","November","December"};

printf("\nEntered your desired year:");


scanf("%d",&year);

if(year%4==0 && year%100!=0 || year%400==0)


{
monthDay[1]=29;
}

startingDay=get_1st_weekday(year);
for(month=0;month<12;month++)
{
days_in_month=monthDay[month];
printf("\n\n------------------%s------------------",months[month]);
printf("\n Sun Mon Tue Wed Thur Fri Sat\n");

for(weekdays=0;weekdays<startingDay;weekdays++)
{
printf(" ");
}

for(day=1;day<=days_in_month;day++)
{
printf("%6d",day);
if(++weekdays>6)
{
printf("\n");
weekdays=0;
}
startingDay=weekdays;
}
}

You might also like