Menu

Add Topic

C Programming

waiting answer July 12, 2021

Leap Year Program In C

Answers
January 20, 2021

Condition for the leap year 

Leap Year

  • If a year is divisible by 400,100 and 4, then the year is a leap year. 
  • If a year is not divisible by 100 and divisible by 4, then this is a leap year.    

Not a leap year

  • if a year is not divisible by 4, then this is not a leap year
  • if a year is not divisible by 400 and divisible bt 4 and 100, then the year is not a leap year

c program to check leap year

    #include 
    int main() {
       int year;
       printf("Input a year: ");
       scanf("%d", &year);
       
       if (year % 400 == 0||year % 4 == 0) {
          printf("Leap Year");
       }else{
           printf("Not a leap year");
       }
       return 0;
    }

Output:

         Input a year: 2018
         Not a leap year    

0 0
January 20, 2021
    #include 
    int main() {
       int year = 2020;
       
       if ((year%400 == 0) || ((year % 4 == 0) && (year % 100!= 0))){
           printf("%d is a leap year", year);
       }else{
           printf("%d is not a leap year", year);
       }
       
       return 0;
    }

Output:

        2020 is a leap year

0 0

Please Login to Post the answer

Leave an Answer