Learn about Check Leap Year Using a switch case statement in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Check Leap Year Using a switch case statement
The below program takes year as user input. Then checks the conditions and display the result using switch-case method.
Source code:
#include<stdio.h>
int main()
{
int year, remainder;
printf("Enter Year: ");
scanf("%d",&year);
remainder=((year%4==0)&&((year%400==0)||(year%100!=0)));
switch(remainder)
{
case 1:
printf("Leap Year");
break;
case 0:
printf("Not Leap Year");
break;
default:
printf("Invalid");
break;
}
return 0;
}
Output:
Enter Year: 2020
Leap Year
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Check Leap Year Using nested if-else
Leap Year Program in C Using if-else statement