Skip to main content

C Program to check Leap Year

Programming Languages

Welcome to coding world

C Program to check Leap Year 

 This program checks whether the input year is leap year or not.

Example: Program to check Leap Year

You can check whether a year is leap or not by using this mathematical logic:

Leap Year:

If a year is divisible by 4, 100 and 400 then it is a leap year.
If a year is divisible by 4 but not divisible by 100 then it is a leap year

Not a Leap Year:

If a year is not divisible by 4 then it is not a leap year
If a year is divisible by 4 and 100 but not divisible by 400 then it is not a leap year

Let’s write this logic in a C Program. To understand this program you should have the knowledge of following C programming topic:

C Programming If..else, Nested if..else

#include <stdio.h>

int main()

{

    int y;

 

    printf("Enter year: ");

    scanf("%d",&y);

 

    if(y % 4 == 0)

    {

            //Nested if else

        if( y % 100 == 0)

        {

            if ( y % 400 == 0)

                printf("%d is a Leap Year", y);

            else

                printf("%d is not a Leap Year", y);

        }

        else

            printf("%d is a Leap Year", y );

    }

    else

        printf("%d is not a Leap Year", y);

 

    return 0;

}

Output:

Enter year: 1991

1991 is not a Leap Year

Popular posts from this blog

Good Morning Wishes

Explore the beauty of Murree | A memorable tour from Lahore to murree | Tour packing tips

Memorable Murree Getaway As we set off from Lahore, the excitement was palpable. The scenic drive to Murree was breathtaking, with lush green hills and winding roads. After a four-hour journey, we arrived in Murree, and the crisp mountain air invigorated us. We spent the day exploring Mall Road, browsing local shops, and savoring delicious food at restaurants. The stunning views of the hills and valleys left us spellbound. As the sun set, we settled into our cozy hotel, feeling grateful for this escape from the city's hustle. The next day, we visited the iconic Patriata Chair Lift (if operational) and took in the panoramic views. Our hotel's scenic location offered breathtaking sunrises and sunsets. As we reluctantly bid farewell to Murree and headed back to Lahore, memories of our time in the hills lingered. The trip was a perfect blend of adventure, relaxation, and rejuvenation. Highlights: - Scenic drive to Murree - Exploring Mall Road and local cuisine - Breathtaking views ...

Ayeza Khan Bridal collection 2021

Pakistan Showbiz Ayeza khan celebrate 10M on Instagram Ayeza Khan & Danish Taimoor love story