C program for a leap year || check leap year program in c - Do Tech Blog

C program for a leap year || check leap year program in c

In this article, we will know how do perform the C program for a leap year.


So first of all people take What is a leap year? How do you create a leap year program in c language?  we will know the explanation of the program. So let's start.


C program for a leap year


What is Leap Year

 The year that comes once in every four years is 366 days. It is called a leap year. There are 365 days in such a year.


Algorithm for find leap year


  1. START
  2. Taking an integer value by the user that will be years.
  3. Assign the value in that integer.
  4. Now we will check if the year is divisible by 4 but not by 100 then there will be "leap year".
  5. Now check if the year is divisible by 400 then there will be "leap year".
  6. Otherwise, "not leap year".
  7. STOP


C Program For A Leap Year


#include <stdio.h>

int main ()

{

int y;

printf ("Enter A Year :"); 

scanf ("% d", & y);

if (((y% 4 == 0) && (y% 100! = 0)) || (y% 400 == 0))

printf ("% d is Leap year", y);

else

printf  (" Not  leap year", y);

return 0;

}


Input:

Enter Year: 2020

Output

2020 is a leap year


Explain this program


  • In this program, an integer value will be Y. In which the year will be assign, in which you have to check whether the entered year is a leap year or not.
  • Now the value of y is intercepted by the user.
  • Now let us use the control statement.
  • In which if statement contains ((y% 4 == 0) && (y% 100! = 0)) || (y% 400 == 0) condition. In which if entered year is divisible by 4 and by 100 If not divisible and divisible by 400, then that year will be called leap year.
  • Else that year will be a not leap year.

No comments :

Post a Comment

;