Program 14:
#include<stdio.h> main() { int year; printf("Enter the year you want to check\n"); scanf("%d",&year); if(year%400==0) { printf("%d is 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); } }Explanation:
- Initialization of variable 'year' for taking user input.
- Then prompting user to give the year of his interest.
- Now we check whether the year is divisible by 400 or 100 or 4
- If the variable is divisible by
- 400 then it is leap year(ex: 2000,2400)
- 100 then it is not a leap year.(ex: 2100 which is divisible by 4 but not with 400)
- 4 then it is leap year.
- Then printing the corresponding printf.