Solved

# Comment to Calendar program

Posted on 2003-03-05
Medium Priority
164 Views
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
Question by:dmuran
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 46

Expert Comment

ID: 8076125

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

LVL 84

Accepted Solution

ozo earned 80 total points
ID: 8077724
#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

LVL 1

Expert Comment

ID: 8078473
Thats a very beautiful code presented by ozo.

gr8 yaar

0

LVL 20

Expert Comment

ID: 10089296
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

jmcg
EE Cleanup Volunteer
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
###### Suggested Courses
Course of the Month11 days, 22 hours left to enroll