Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python program to check Leap Year|Python language

C language Leap Year Program|C Program

Posted on November 18, 2020November 18, 2020

Table of Contents

  • C language Leap Year Program|C Program
    • Leap year program in C language
      • Check whether the given year is leap or not- using if-else if
      • Check whether the given year is leap or not- using Nested if
      • Check whether the given year is leap or not- using if else
      • Check whether the given year is leap or not- using ternary operator
      • Check whether the given year is leap or not- using function
    • Related

C language Leap Year Program|C Program

In this article, we will discuss the concept of C language Leap Year Program

In this Program, we are going to learn how to make sure the given year whether leap year or not using different methods in C language.

This is done using if-else , if-else if-else, Nested -if,ternary operator and function in C language.

Leap year program in C language

Check whether the given year is leap or not- using if-else if

In this program, we are going to learn how to make sure the given year whether leap year or not using if-else if statements in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int year;
    printf("Enter a year for check leap or not\n");
    scanf("%d",&year);
    if(year%400==0){
   printf("%d is a leap year ",year);
}
else if(year%100==0){
  printf("%d is not a leap year ",year);
}

   else if(year%4==0){
      printf("%d is a leap year ",year);
   }
     else{
     printf("%d is not a leap year ",year);
}
getch();
    return 0;
}

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

Case 1

Enter a year for check leap or not
2040
2040 is a leap year

Case 2

Enter a year for check leap or not
2050
2050 is not a leap year

 

Check whether the given year is leap or not- using Nested if

In this program, we are going to learn how to make sure the given year whether leap year or not using Nested if statements in C language

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int year;

    printf("Enter a year for check leap or not\n");
    scanf("%d",&year);

   if(year%4==0){
     if(year%100==0){
           if(year%400==0){
     printf("%d is a leap year ",year);
        }else
    printf("%d is not a leap year ",year);
    } else
    printf("%d is a leap year ",year);
  }else
     printf("%d is not a leap year ",year);
getch();
    return 0;
}

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

Case 1

Enter a year for check leap or not
2120
2120 is a leap year

Case 2

Enter a year for check leap or not
2100
2100 is not a leap year

Check whether the given year is leap or not- using if else

In this program, we are going to learn how to make sure the given year whether leap year or not using if else statements in C programming

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int year;

    printf("Enter a year for check leap or not\n");
    scanf("%d",&year);

   if ((year%400==0)||((year%4==0)&&(year%100!=0))){
     printf("%d is a leap year ",year);
}
     else{
     printf("%d is not a leap year ",year);
}
getch();
    return 0;
}

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

Case 1

Enter a year for check leap or not
2052
2052 is a leap year

Case 2

Enter a year for check leap or not
2200
2200 is not a leap year

 

Check whether the given year is leap or not- using ternary operator

In this program, we are going to learn how to make sure the given year whether leap year or not using ternary operator in C programming

Program 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int year;
    printf("Please Enter year for check leap: \n");
    scanf("%d",&year);
    (year%4==0 && year%100!=0)? printf("The entered year is a leap year"):(year%400==0)?
    printf("The entered year is a leap year")
:printf("This is not a leap year");
getch();
    return 0;
}

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

Case 1

Please Enter year for check leap:
2024
The entered year is a leap year

Case 2

Please Enter year for check leap:
2014
This is not a leap year

 

Check whether the given year is leap or not- using function

In this program, we are going to learn how to make sure the given year whether leap year or not using function in C programming

Program 5

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

int leapYear(int y)
{
    if((y%400==0)||((y%4==0)&&(y%100!=0)))
       return 1;
    else
        return 0;
}

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

Case 1

Please Enter year for check leap:
2044
2044 is a leap year

Case 2

Please Enter year for check leap:
2014
2014 is not a leap year

 

Suggested for you

Operator in C language

if statements in C language

Nested if statements in C language

function in C language

 

Similar post

Java Leap Year Program|Java Program

C++ Leap Year Program|C++ Program

Python Leap Year Program|Python Program

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes