Sep 7, 2010 at 10:49am UTC
Any year is input through the keyboard, write a program to determine whether its leap year or not.
Sep 7, 2010 at 1:16pm UTC
2005
Nope, it isn't
2012
Yeah!
Sep 7, 2010 at 3:03pm UTC
I wrote it on a cocktail napkin but when I tried to compile it the stupid thing jammed in my DVD drive.
Thanks a lot! :-(
mhadel: You have to try writing it yourself. We'll help you but we won't do your homework.
Sep 8, 2010 at 2:42pm UTC
# include <iostream>
using namespace std;
int main ()
{
int year;
cout << "input year: ";
cin >> year;
if ( year % 4 == 0 )
cout << "\nYeah!" << endl;
else
cout << "\nNope, it isnt"<< endl;
return 0;
}
is that what you are looking for?
Sep 8, 2010 at 3:58pm UTC
Sorry. Fails at year 100. But you're close.
FYI, the idea is NOT to do someones homework but rather to help them do it.
Sep 8, 2010 at 4:07pm UTC
Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.
Sep 8, 2010 at 4:21pm UTC
The wikipedia link posted by Mihay07 even has pseudo code for that. Just translate it to C++.
Sep 8, 2010 at 4:38pm UTC
Here:
(define (f n) (or (= (remainder n 400) 0) (and (= (remainder n 4) 0) (not (= (remainder n 100) 0)))))