Wednesday 24 July 2013

Chapter 2 solutions problem[C](c)

Question-Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not.
(Hint: Use the % (modulus) operator)
solution -
I am pretty much sure many people really don't know exactly, which year is leap year. common misconception is if the year is divisible by 4. it's a leap year. this is only partially correct. what about year 1700. it's not leap year. so, correct concept is leap either year should be divisible 4 and 400, or it should be divisible by 4 and not completely divisible by 100. if you didn't understand . don't worry. program would make it clear for you.

#include<stdio.h>
int main()
{
int year;
printf("Enter any year\n");
scanf("%d",&year);
if(year%4==0&&year%400==0||year%100!=0)
printf("Leap year\n");
else
printf("not a leap year\n");
return 0;
}  

No comments:

Post a Comment