Write a C Program to Check Leap Year or Not
Question No. 02
- Write a C program to check whether it's a Leap Year or Not.
#include <stdio.h>
int main () {
int year;
printf("Enter The Year:\n");
scanf("%d", &year);
if ( year % 400 == 0) {
printf("%d is leap year", year);
} else if (year % 100 == 0) {
printf("%d is not a leap year", year);
} else if (year % 4 == 0) {
printf("%d is leap year", year);
} else {
printf("%d is not a leap year", year);
}
return 0;
}
Output: Enter The Year
2023
2023 is not a leap year.
Algorithm
- Step 1: Start,
- Step 2: read "Year" from user input,
- Step 3: if (year % 400 ==0)
- step3.1: True, Print "Year is a leap year,
- step3.2: False, jump to step 4,
- Step 4: if (year % 100 == 0),
- step 4.1: True, Print "Year Is not a leap year",
- step 4.2: False, jump to step 5,
- Step 5: if(year % 4 == 0),
- step5.1: True, print "Year is a leap year,
- step 5.2: "Year Is not a leap year",
- Step 6: Stop.
Flow Chart
Genrerating Link.... 15 seconds.
Your Link is Ready.