- A year is said to be leap year if it is divisible by 4.
- For example 2004 , 2008,2012 and 2016.
- A year is also a leap year if it is divisible by 100 and divisible by 400.
- For example 1600 and 2000 etc.
- A leap year of February moth will have 29 days.
- Let us see an example C program to check a year is leap year or not using simple if condition.
- First we need to check a year is divisible by 4 or not.
- If yes then again one more condition if it is divisible by 100 and 400. if it is divisible by 100 then it should be divisible by 400 then only it is leap year.
- c program code to find leap year using if else
Program #1: Write a C program to check a year is leap year or not without using any function.
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int year;
- printf("Enter a year to check if it is a leap year or not \n");
- scanf("%d", &year);
- if ( year%400 == 0)
- printf("%d is a leap year.\n", year);
- else if ( year%100 == 0)
- printf("%d is not a leap year.\n", year);
- else if ( year%4 == 0 )
- printf("%d is a leap year.\n", year);
- else
- printf("%d is not a leap year.\n", year);
- return 0;
- }
Output:
No comments