0

I'm new to C programming. I could not understand how to write the following programs.

1. Any year is input through keyboard. Write aprogram to determine whether it is a leap year or not.

5
Contributors
4
Replies
5
Views
13 Years
Discussion Span
Last Post by let us c
0

That's simple,lol

Just divide the year by 4 using modulus (%).

if(year % 4 == 0) cout<< "Yahoo a leap year";

0

A complete leap year calculation is something along these lines....

A year is a leap year if it can be divided by 4 with no remainder....
EXCEPT if it is divisible by 100 with no remainder....
EXCEPT if it is divisible by 400 with no remainder.

So 2004 is a leap year (divisble by 4)
1900 was NOT (divisible by 100)
2000 WAS (though it was divisible by 100, it was also divisible by 400)

0

I'm new to C programming. I could not understand how to write the following programs.

1. Any year is input through keyboard. Write aprogram to determine whether it is a leap year or not.

its a very basic prog.

take a user i/p. then chk if it is divisible by 100(eg.1900,1800,2000)
if yes divide the number by 400(use mod fn). if it is giving no rem,then it is a leap yr.

if no. is not a multiple of 100, divide by 4 and get ur ans.

all the best

0

the condition must be:
if((y%4==0&&y%100!=0)!!(y%400=-0)) pf("leap year") ......it goes like this

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.