Search This Blog


Saturday, 20 April 2019

C Program to Find if a given Year is a Leap Year

WELCOME BACK CODERS , HOPE YOU ARE ENJOYING OUR BLOGS , WILL LOVE TO SEE YOU AGAIN ON OUR BLOGS.

leap year is a year which has 366 days. The extra day is the 29th February. There is a leap year every four years.

IN THIS PROGRAM THE USER NEEDS TO ENTER A YEAR AND THEN THE PROGRAM WILL FIND IF A GIVEN YEAR IS A LEAP YEAR.


Problem Solution
1. Take a year as input.
2. Check whether a given year is divisible by 400.
3. Check whether a given year is divisible by 100.
4. Check whether a given year is divisible by 4.
5. If the condition at step 2 and 4 becomes true, then the year is a leap year.
6. If the condition at step 3 becomes true, then the year is not a leap year.

CODE

 void main()
 {

     int year;
  
     printf("Enter a year \n");
     scanf("%d", &year);
     if ((year % 400) == 0)
         printf("%d is a leap year \n", year);
     else if ((year % 100) == 0)
         printf("%d is a not 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);
 }




OUTPUT



No comments:

Post a Comment