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

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....


Thanks in advance...
0
dmuran
Asked:
dmuran
1 Solution
 
Kent OlsenData 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
 
ozoCommented:
#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
 
sarda_rameshCommented:
Thats a very beautiful code presented by ozo.

gr8 yaar

0
 
jmcgOwnerCommented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now