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
- C program
- 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:
إرسال تعليق