Check Leap Year in C and C++ programming


In this page you can learn to make a piece of code to find the given year is leap year or not. The program has been given in two programming languages

  1. C program
  2. C++ program

The codes where given below with an input and output

 

C PROGRAM TO FIND LEAP YEAR :

// You are using GCC
#include<stdio.h>
int main()
{
    int year;
    scanf("%d",&year);
    if(year%400==0)
    {
        printf("%d is an leap year",year);
    }
    else if(year%100==0)
    {
        printf("%d is not an leap year",year);
    }
    else if(year%4==0)
    {
        printf("%d is an leap year",year);
    }
    else
    {
        printf("%d is not an leap year",year);
    }
}


C++  PROGRAM TO FIND LEAP YEAR:

// You are using GCC
#include<iostream>
using namespace std;
int main()
{
    int year;
    cin>>year;
    if(year%400==0)
    {
       cout<<year<<" is an leap year"<<endl;
    }
    else if(year%100==0)
    {
        cout<<year<<" is not a leap year"<<endl;
    }
    else if(year%4==0)
    {
         cout<<year<<" is an leap year"<<endl;
    }
    else
    {
         cout<<year<<" is not a leap year"<<endl;
    }
}

INPUT:

2021

2012

OUTPUT:

2021 is not a leap year
2012 is an leap year 

0 تعليقات

إرسال تعليق

Post a Comment (0)

أحدث أقدم