You are here:

C/How enter Leap years into programs

Advertisement


Question
I want to write a program that read today's date
(such as 13/07/2004) and then I type number N
(N>400)and i expect the program that tell me what is the date of N days ago.
But i have a problem:as you know we have 3years=365 days and 1year=366days every 4years
I should do this to my program  it means the program must know that the last years have 365days or 366days.
Please guide me to solve this problem


Answer
By knowing the year number, you can find out if it is a LEAP year.
For example, year 2004 gets divided by 4. So, it is a LEAP year.
So, make the same check in your code. For that make use of % operator.

Start writing the algorithm. If you get into any problem revert back. I will try to help you.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.