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

Ayeza Khan Bridal collection 2021

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

Key Ecommerce Leader (KEL) Pakistan Awards Event 2024 | Pakistan KEL Awards Winner Tayyub Hussnain (Norwich Street Wear) | 2024 Alibaba.com Pakistan Key E-commerce Leader Winner

 Key Ecommerce Leader (KEL) Pakistan Awards Event 2024 On August 20, 2024, Alibaba.com organized an exceptional event at the Pearl Continental Hotel in Lahore. Participants gained insights into global business strategies and discovered the vast opportunities available through Alibaba.com. In an exciting development, Alibaba.com announced the launch of Trade Assurance in Pakistan by the end of August 2024, representing a significant advancement for the Pakistani market. Featured speakers included: 🌟 Andrew Zheng - Vice President, Alibaba.com 🌟 Vianne Wang - Head of Global Supply Chain, Alibaba.com 🌟 Winni Chen - Merchant Development Manager The event was a resounding success, enhancing confidence in the future of eCommerce in Pakistan! 💪🎉 During the event, six successful business owners were invited to share their stories and insights. Mr.Tayyub Hussnain stood out with his inspiring success story and impressive leadership skills, captivating the audience and judges alike. Ho...

Good Morning Wishes