Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is code for calendar in C but now this calendar shows days from Sunday to Saturday, but i would like to show from Monday

Here is code for calendar in C but now this calendar shows days from Sunday to Saturday, but i would like to show from Monday to Sunday. Any idea, thank you :) .ps can you try if works for you correctly? because when i type date for march, 2018 so calendar shows bad information. :)

#include

void days(int,int,int,int,int,int);

int month(int,int);

int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};

#define TRUE 1

#define FALSE 0

int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

char *months[]=

{

" ",

" January",

" February",

" March",

" April",

" May",

" June",

" July",

" August",

" September",

" October",

" November",

" December"

};

int inputyear(void)

{

int year;

printf("Please enter a year (example: 1999) : ");

scanf("%d", &year);

return year;

}

int inputmonth(void)

{

int month;

printf("Please enter a month (example: 1-12) : ");

scanf("%d", &month);

return month;

}

int determinedaycode(int year)

{

int daycode;

int d1, d2, d3;

d1 = (year - 1.)/ 4.0;

d2 = (year - 1.)/ 100.;

d3 = (year - 1.)/ 400.;

daycode = (year + d1 - d2 + d3) %7;

return daycode;

}

int determineleapyear(int year)

{

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

{

days_in_month[2] = 29;

return TRUE;

}

else

{

days_in_month[2] = 28;

return FALSE;

}

}

void calendar(int year, int daycode)

{

int month, day;

for ( month = 1; month <= 12; month++ )

{

printf("%s", months[month]);

printf(" Sun Mon Tue Wed Thu Fri Sat " );

// Correct the position for the first date

for ( day = 1; day <= 1 + daycode * 5; day++ )

{

printf(" ");

}

// Print all the dates for one month

for ( day = 1; day <= days_in_month[month]; day++ )

{

printf("%2d", day );

// Is day before Sat? Else start next line Sun.

if ( ( day + daycode ) % 7 > 0 )

printf(" " );

else

printf(" " );

}

// Set position for next month

daycode = ( daycode + days_in_month[month] ) % 7;

}

}

void calendarm(int year, int daycode, int month)

{

int day;

printf("%s", months[month]);

printf(" Sun Mon Tue Wed Thu Fri Sat " );

// Correct the position for the first date

for ( day = 1; day <= 1 + daycode * 5; day++ )

{

printf(" ");

}

// Print all the dates for one month

for ( day = 1; day <= days_in_month[month]; day++ )

{

printf("%2d", day );

// Is day before Sat? Else start next line Sun.

if ( ( day + daycode ) % 7 > 0 )

printf(" " );

else

printf(" " );

}

// Set position for next month

daycode = ( daycode + days_in_month[month] ) % 7;

}

int main(void)

{

int year, daycode, leapyear,month,c;

int a1,b1,c1,a2,b2,c2;

printf(" choose these option from menu");

printf(" 1.View calendar for specified month in selected year");

printf(" 2.View the calendar for the specified year");

printf(" 3.Find the number of days between 2 selected dates");

printf(" 4.End the program");

scanf("%d",&c);

switch(c)

{

case 1:

year = inputyear();

month = inputmonth();

daycode = determinedaycode(year);

determineleapyear(year);

calendarm(year, daycode,month);

printf(" ");break;

case 2:

year = inputyear();

daycode = determinedaycode(year);

determineleapyear(year);

calendar(year, daycode);

printf(" ");break;

case 3:

printf(" Enter first date(dd mm yyyy) : ");

scanf("%d%d%d",&a1,&b1,&c1);

printf(" Enter second date(dd mm yyyy) : ");

scanf("%d%d%d",&a2,&b2,&c2);

if(c2>=c1)

days(c1,c2,b1,b2,a1,a2);

else

days(c2,c1,b2,b1,a2,a1);

break;

case 4: break;

default:printf(" Enter correct value");break;

}

}

void days(int y1,int y2,int m1,int m2,int d1,int d2)

{

int count=0,i;

for(i=y1;i

{

if(i%4==0)

count+=366;

else

count+=365;

}

count-=month(m1,y1);

count-=d1;

count+=month(m2,y2);

count+=d2;

if(count<0)

count=count*-1;

printf(" The no. of days b/w the 2 dates = %d days",count);

}

int month(int a,int yy)

{

int x=0,c;

for(c=0;c

{

if(c==1)

{

if(yy%4==0)

x+=29;

else

x+=28;

}

else

x+=mon[c];

}

return(x);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions