Leap Year Program in C Using Function

Leap year program in c using function to find the year is a leap year or not using c programming functions for beginners to learn c.

Function Definition in C

A function is a group of statements that cooperate to accomplish a goal. 

Every C program has at least one function, main(), and even the most basic programs can have multiple functions defined.

A function declaration specifies the name, return type, and parameters of the function. 

A function is a collection of statements that accomplishes a specific goal.

If Else Statement in C

The if statement evaluates the test expression enclosed in parenthesis (). 

The statements in the if body are executed if the test expression returns true.

If the test expression is false, statements inside the body of if are not executed. 

If a specified condition is true, the if/else statement executes a block of code. 

Another block of code can be executed if the condition is false.

#include <stdio.h>
#include <stdlib.h>
int func(int);
int main()
{
int year;
printf("Enter The Year\n");
scanf("%d",&year);
if(func(year))
printf("%d is Leap Year",year);
else
printf("%d is Not Leap Year",year);
return 0;
}
int func(int y)
{
if((y%400==0)||((y%4==0)&&(y%100!=0)))
return 1;
else
return 0;
}

Output:

Enter The Year
2020
2020 is Leap Year