?
Solved

Comment to Calendar program

Posted on 2003-03-05
5
Medium Priority
?
164 Views
Last Modified: 2010-04-15
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....


Thanks in advance...
0
Comment
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
  • Learn & ask questions
5 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
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

by:
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

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

gr8 yaar

0
 
LVL 20

Expert Comment

by:jmcg
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
accept answer ozo.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
Video by: Grant
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

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question