Check value

C program for check whether given year is leap using function

C program for check whether given year is leap using function

In this article, we will discuss the concept of C program for check whether given year is leap using function

In this post, we are going to learn how to write a program to check  the given year is leap or not, using function  in C  programming language

Check if the given year is a leap

Check whether given year is leap using function

What is leap year

A normal year contains 365 days but a leap year contains 366 days

leap year is occurring once every four years, which has 366 days including 29 February as an intercalary day. it is called leap year

Century year

The century year is ending with 00

Ex 2000, 2100, 2200

a century year may be a leap year but it is not compulsory

 

How to find the leap year

if The given year is perfectly divisible by 4 , it is a leap year(except century year)

only if it is perfectly divisible by 400, the century year is a leap year,
a century year should be divisible by 4 and 100 both
a non century year should be divisible only by 4

 

Code to check leap year using function

Here, The program allows the user to enter the year and then it will check the year is a leap year or not, using function in C  language

Program 1

#include <stdio.h>
#include <stdlib.h>
int leapYear(int);//function prototype
int main()
{
    int year;//variable declaration
    printf("Enter the year for check leap\n");
    //Ask input from the user
    scanf("%d",&year);
    //store the value in the year variable
    if(leapYear(year))//function definition
        printf("%d is a leap year",year);
    else
        printf("%d is not a leap year",year);
        getch();
    return 0;
}

int leapYear(int y)//function definition
{
    if((y%400==0)||((y%4==0)&&(y%100!=0)))
        //Leap year if perfectly divisible by 400
        //Leap year if perfectly divisible by 4
        //but if not divisible by 100
       return 1;
    else//all other years are not leap year
        return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the year for check leap
2028
2028 is a leap year


Case 2

Enter the year for check leap
2030
2030 is not a leap year

 

Suggested post

if statements inn C language

Nested if statements in C language

Data type in C language

Variable in C language

Operator in C language

input output function in C language

 

Similar post

Java program to find leap year

C program to find leap year

C++ program to find leap year

Python program to find leap year

C++ program for check whether given year is leap using function

Python program for check whether given year is leap using function

C program for check whether given year is leap using function

 

Java code to check if the given year is a leap using method
Python program for check whether given year is leap using function
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago