Leap year program in C


 


Example

See the below example in which we check a leap year by taking input from user:

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. void main() {  
  4.     int year;  
  5.     printf("Enter a year: ");  
  6.     scanf("%d", &year);  
  7.     if(((year%4==0) && ((year%400==0) || (year%100!==0))  
  8.     {  
  9.         printf("%d is a leap year", &year);  
  10.     } else {  
  11.         printf("%d is not a leap year", &year);  
  12.     }  
  13.     getch();  
  14. }  

Output

See the below outputs for different input values:

Test 1:

Enter a year: 2004
2004 is a leap year