/* */ Click to Join Live Class with Shankar sir Call 9798158723

check leap year or not in C using if else ?

Q.) W.A.P to check the leap year or not in C using if else ?
 int main()
     int year;
     printf("enter a year :\n");
     if (year%4==0)
        printf("This is a leap year");
     printf( "This is not a leap year");
enter a year :
2020      /* say year = 2020 */.
This is a leap year

Program Explanation

Step 1: Include header files (#include<stdio.h> and #include<conio.h>).

Step 2: Start with main function with return type.

Step 3: parenthesis to start and end the program { }.

Step 4: declare variables with data type i.e, 'year' is an integer type so we use "int" data type.

Step 5: Use output function printf() to print the output on the screen.

Step 6: Use input function scanf() to get input from the user.

Step 7: Here, we have to check whether the entered year is a leap year or non leap-year by using if-else condition, Here, we use the arithmetic operator(i.e, %) as well as the assignment operator (i.e, ==) to check condition. if condition checks whether 'year' is fully divisible by 4 or not.

  • if this condition is true, then it will execute if block, which will print the output as this is a leap year.
  • if the condition is not true then it will execute else block and print the output as this is not a leap year.

Step 8: using getch() function to hold the screen.