Leap Year Problems

This is a discussion on Leap Year Problems within the C Programming forums, part of the General Programming Boards category; Hey all,
I have the following problem...
"A leap year is any year divisible by 4, unless the year is ...

#include <stdio.h>
char line[10];
int year;
int leap1;
int leap2;
int leap3;
int main()
{
printf("Enter the year to find out if it is a leap year: ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &year);
/*A leapyear is any year divisible by 4, unless the year is divisible by 100 but not 400.*/
leap1 = year % 4;
leap2 = year % 100;
leap3 = year % 400;
if (leap1 == 0)
if (leap2 != 0)
if (leap3 ==0)
{
printf("%d is a leapyear\n", year);
}else{
printf("%d is not a leapyear\n", year);
}
return(0);
}

...but it is not working. I came across this (Check for a leap year) which works and is similar to mine except it uses || and && which I can't use for this problem.

you would need an else for every if, and would need to structure the messages properly, yours will only say it's a leap year when it's not divisible by 100 and is divisible by 400 (guess how many numbers satisfy that requirement (I'll give you a hint, don't divide by it))

Ok, I did miss that. So use some other method of nesting if-statements so that the printout only requires one set of if-statement. E.g. initialize a variable to "leapyear", use multiple if-statements to "not leapyear", then use a single if to determine whether the variable was set to "leapyear" or "not leapyear"

Obviously "leapyear" and "not leapyear" probably should be the values 1 and 0 (or the other way around).

Ok, I did miss that. So use some other method of nesting if-statements so that the printout only requires one set of if-statement. E.g. initialize a variable to "leapyear", use multiple if-statements to "not leapyear", then use a single if to determine whether the variable was set to "leapyear" or "not leapyear"

Obviously "leapyear" and "not leapyear" probably should be the values 1 and 0 (or the other way around).

--
Mats

or just have it print out "I'm a leap year"/"I'm not a leap year"

@jc99
200 is not a leap year but 400 is, you were interpreting it wrong in your code (it would still need to use else though)