Write a C C++ program to check leap year

Write a C C++ program to check leap year

C Language की विशेषताओं एवं शक्तियों को जानने के लिए देखें—Features and Powers of C

If statement और इसके विभिन्न प्रकारो को जानने के लिए देखें—If statements in C

Flowchart to check leap year

Finding given year is leap or not flowchart

C program to check leap year

#include<stdio.h>
int main()
{
    int y;
    printf("Enter an year: ");
    scanf("%d",&y);
    if(y%4==0&&y%100!=0||y%400==0)
    {
        printf("Leap year");
    }
    else
    {
        printf("Not a leap year");
    }
    return 0;
}

C++ program to check leap year

#include<iostream>
using namespace std;
int main()
{
    int y;
    cout<<"Enter an year: ";
    cin>>y;
    if(y%4==0&&y%100!=0||y%400==0)
    {
        cout<<"Leap year";
    }
    else
    {
        cout<<"Not a leap year";
    }
    return 0;
}

Output of C C++ program to check leap year

Enter a year: 2020
leap year
Enter a year: 2021
Not a leap year

Other selection logic programs in C C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Greater in two numbers (if else)
  4. Finding grade from percent (else if ladder)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer