Skip to content
Home » C Programs » C Program For Leap Year Using Conditional Operator

C Program For Leap Year Using Conditional Operator

Basic c program for leap year using conditional operator. In this program we can check the program to leap year using conditional operator for beginners.

Conditional Operator in C

Conditional Statements are used in C programming to make decisions based on conditions. When there is no condition surrounding the statements, they are executed consecutively. 

It is also known as branching because a computer determines which statement to execute based on the outcome of the examined condition.

Operator Definition in C

An operator is a symbol that performs an operation on a variable or value. There are many different types of operators, including arithmetic, logical, conditional, relational, bitwise, and assignment operators. C also has several specific operators such as sizeof(), pointer operator, reference operator, and so on. Operators are very important to execute the c program for leap year using conditional operator for beginners.

Leap Year Definition in C

The year number must be divisible by four to be a leap year — except for end-of-century years, which must be divisible by 400. This signifies that 2000 was a leap year, whereas 1900 was not. The years 2020, 2024, and 2028 are all leap years.

C Program For Leap Year Using Conditional Operator

#include <stdio.h>
int main()
{
int year;
printf("Enter The Year");
scanf("%d", &year);
(year%4==0 && year%100!=0) ? printf("Leap Year") :
(year%400 ==0 ) ? printf("Leap Year") : printf("Common Year");
return 0;
}

Output:

Enter The Year2020
Leap Year