C program to check year is leap year or common year

Ex: Write a C program to check given year is leap year or common year. How to write a C program to check given year is leap or not. C program to check given year is leap year or common year.


  What  is leap year ?


We all know in the regular year has 365 days.  But in the leap year one day has extra. means leap year has 366 days.



Input from user:

Enter the year: 2020


Expected output:

Given year is leap year.





  Step by step logic of the program:


1. Firstly get input year  from  user. variable say year.

2.  After that use if-else statement to check given condition if(year%400==0) or(year%4==0 and year%100!=0).

3. If above conditions are true then print given year is leap year.

4. Otherwise we print given year is common year.





  C program to check year is leap year or common year :



#include<stdio.h>
int main()
{
int year;

printf("Enter the year\n");
scanf("%d",&year);

if((year%400==0)||(year%4==0 && year%100!=0))
{
printf("Given year is leap year");
}
else
{
printf("Given year is common year");
}

return 0;
}



Above program shows the following output:




No comments:

Post a Comment

If you have any doubts, please discuss here...👇