This article show the program to find all the leap years between a range in c/c++.
C Code for Leap Years between a Range
#include
#include
int main()
{
clrscr();
int a,n,i,k=0;
cout<<"\"This program will show Leap Years between a range. \""<<endl<<endl;
cout<<"What is the starting year ?. Give a starting year. "<<endl; cin>>a;
cout<<"What is the ending year ?. Give a ending year. "<<endl; cin>>n;
cout<<endl;
cout<<"Leap Years between "<<a<< " to "<<n<<" are :"<<endl;
for(i=a;i<=n;i++)
if(((i%400==0) || (i%100 !=0)) && ( i%4==0))
{
cout<<i<<" ";
k++;
}
if(k==0)
{
cout<<0<<endl;
cout<<"It means there is no leapyears between "<<a<<" to "<<n;
}
getch();
}
//Leap Year
#include
void main()
{
int year1,i,year2;
printf(“Enter the start year and end year:”);
scanf(“%d %d”,&year1,&year2);
printf(“\n%d to %d”,year1,year2);
printf(“\nLEAP YEAR:”);
for(i=year1;i<=year2;i++)
{
if(i%4==0)
{
if(i%400==0 || i%100==0)
{
printf("%d\t",i);
}
else
{
printf("%d\t",i);
}
}
}
printf("\nNOT LEAP YEAR:");
for(i=year1;i<=year2;i++)
{
if(i%4!=0)
{
if(i%400!=0 || i%100!=0)
{
printf("%d\t",i);
}
else
{
printf("%d\t",i);
}
}
}
}