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

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...

Pakistan celebrities real ages 2021

  Pakistani Celebrities Ages 2021 A few celebrities hide their age since they have to be shape us get it that they are still energetic. So let’s take a see at the Veritable Age of Pakistani Celebrities and see which celebrity ceaselessly lie around his/her age. 1: Ayeza Khan 15 January 1987 2: Mehwish Hayat 6 January 1988 3: Saba Qamar 5 April 1987 4: Sajal Alay 17 January 1994       5: Sara Khan 14 July 1992 6: Iqra Aziz 24 November 1997     7: Alizeh Shah 9 June 2000 8: Zara Noor Abbas 13 March 1991 9: Saboor Aly 3 March 1995 10: Hina Altaf 2 January 1992 11: Sana Javed   25 March 1993 12: Momal Sheikh   6 April 1986 13: Hiba Bukhari 27 July 1993 14: Hira Mani 27 February 1989 15: Aiman Khan 20 November 1998 16: Minal Khan 20 November 1998 17: Kinza Hashmi 7 March 1997 18: Kubra Khan  16 June 1993 19: Mawra Hoccane 28 September 1992 20: Urwa Hoccane 2 July 1991 21: Ha...

Good Morning Wishes