Testing if a number is an integer

Dec 9, 2012 at 6:00am
I have searched for quite some time now and I cannot figure out how to input a year like 2000 and divide it by 4. Then test to see if it is an integer or a float number.
Dec 9, 2012 at 6:52am
Do you want to check for leap years? In that case you can use the modulo operator and check if the result is equal to 0
Dec 9, 2012 at 7:41am
I am fairly new to programming. How exactly would I do that?
Dec 9, 2012 at 8:02am
The modulo operator in C is %. It gives the remainder in a division between integers (doesn't work with floats at all)
For example 7 % 3 == 1. The quotient is 2 and the remainder is 1

This pseudocode is copypasted from wikipedia
if year modulo 400 is 0 then
is_leap_year
else if year modulo 100 is 0 then
not_leap_year
else if year modulo 4 is 0 then
is_leap_year
else
not_leap_year
Dec 9, 2012 at 8:05am
You would want x % y = 0, meaning the remainder of x / y is 0 meaning that the final result is a whole number or an integer.
Dec 9, 2012 at 8:44am
Alright thank you guys. I got the program working. And i learded what a modulo operator is!
Topic archived. No new replies allowed.