Menu

Add Topic

Forum

waiting answer January 20, 2021

Write a 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 <stdio.h>
    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 <stdio.h>
    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