• Status: Solved
• Priority: Medium
• Security: Public
• Views: 165

# Comment to Calendar program

BTW.... I realize that I didn't give the specific part where I'm stuck so it might look like I want you to do the job for me...
What I need is a peace of code that will determine how to:
1. calculate the last day of previous year... (if you type in 2000 it should calculate the last day of 1999 and that will be my start point)

2. I need to know how to determine the leap year...

This are the two peaces of info. I need I think I can do the rest....

0
dmuran
1 Solution

Data Warehouse Architect / DBACommented:

1)  What do you mean by the last day of the previous year?  Date, day of the week, etc?

The Date is easy:

fprintf (DateString, "%4.4d,1231", Year-1);

Day of the week takes a bit more calculating.  I'll be glad to post the source if you need it.

Here's the general rules for determining leap year:

if (year mod 4 != 0)
{use 28 for days in February}
else if  (year mod 400 == 0)
{use 29 for days in February}
else if (year mod 100 == 0)
{use 28 for days in February}
else
{use 29 for days in February}

Kdo
0

Commented:
#include <stdio.h>
main(int argc, char *argv[]){
long int y,d;
char *wd[]={"Sun","Mon","Tues","Wednes","Thur","Fri","Satur","Sun"};
y = atoi(argv[1]);
y -= 1;
d = y*365 + y/4 - y/100 + y/400;
printf("The last day of %d is %sday\n",y,wd[d%7]);
}
0

Commented:
Thats a very beautiful code presented by ozo.

gr8 yaar

0

OwnerCommented:
Nothing has happened on this question in more than 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to