September 30, 2020
c-program c ++

C or C++ Program to Show Leap Years between a Range

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();
}

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

One thought on “C or C++ Program to Show Leap Years between a Range

  1. //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);
    }
    }
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *