Check the year is leap year or not C program
/*
Name : C source program
Author : Funny Coder(Maniruzzman Akash)
It's a free code. You can use it anywhere
*/
#include <stdio.h>
int main(){
int year;
printf("\nEnter any year to check: ");
scanf("%d", &year);
if(year % 4 == 0) //Check devided by 4 or not
{
if( year % 100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
}
else
printf("%d is a leap year.\n", year );
}
else{
printf("%d is not a leap year.\n", year);
}
return 0;
}
Someone think that only devided 4 is a leap year. But that's false. That code is :
#include <stdio.h>
int main(){
int year;
printf("\nEnter any year to check: ");
scanf("%d", &year);
if(year % 4 == 0) //Check devided by 4 or not
{
printf("%d is a leap year.\n", year );
}else{
printf("%d is not a leap year.\n", year);
}
return 0;
}
The error out put of this code is :
But 3000 is never be a leap year. So,follow the first code.
No comments:
Post a Comment