• 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.



  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(){
  5.     
  6.     int year;
  7.     printf("Enter a year to check if it is a leap year or not \n");
  8.     scanf("%d", &year);
  9.  
  10.     if ( year%400 == 0)      
  11.     printf("%d is a leap year.\n", year);     
  12.     else if ( year%100 == 0)      
  13.     printf("%d is not a leap year.\n", year); 
  14.          
  15.     else if ( year%4 == 0 )      
  16.     printf("%d is a leap year.\n", year);
  17.     
  18.     else      
  19.     printf("%d is not a leap year.\n", year); 
  20.  
  21.   return 0;
  22.     
  23. }


 Output:


leap year in c program


Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu