C Examples

WAP in C to Check leap year or not using conditional operators

The Program in C using conditional operators to determine whether a year entered through the keyboard is a leap year or not is given below:

#include <stdio.h>

int main() {
    int year;
    printf("Enter a year: ");
    scanf("%d", &year);

    (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? printf("%d is a leap year.", year) : printf("%d is not a leap year.", year);

    return 0;
}

Output:

Enter a year: 2000
202000 is a leap year.

Pro-Tips💡

This program prompts the user to enter a year, then uses the ternary operator (? 🙂 to determine if the year is a leap year or not.

A leap year is a year that is divisible by 4, except for end-of-century years which must be divisible by 400.

This program checks if the year is divisible by 4, and if it is, then it checks if it is not divisible by 100 or if it is divisible by 400.

If the first condition is true then it will output leap year else not a leap year.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X