C Program to Check Leap Year

Rate this post

 

 A year is a leap year if −
  • It is evenly divisible by 100
    • If it is divisible by 100, then it should also be divisible by 400
  • Except this, all other years evenly divisible by 4 are leap years.
leap year in c
leap year in c

------------------------------------------------------------------


#include <stdio.h>

int main()
{
    int year;

    printf("Enter a year: ");
    scanf("%d",&year);

    if(year%4 == 0)
    {
        if( year%100 == 0)
        {
            // year is divisible by 400, hence the year is a leap year
            if ( year%400 == 0)
                printf("%d is a leap year.", year);
            else
                printf("%d is not a leap year.", year);
        }
        else
            printf("%d is a leap year.", year );
    }
    else
        printf("%d is not a leap year.", year);
    
    return 0;
}

 

Output:

Enter a year: 1900
1900 is not a leap year.

Related Posts

  • 53
    This program is written in C Language using graphics. This will show day, month, date, current time and year as output. #include <graphics.h> #include <time.h> // driver code int main() { // DETECT is a macro defined in // "graphics.h" header file int dt = DETECT, gmode, midx, midy; long current_time;…
    Tags: program, write, year, language, learn
  • 51
    This is a simple calculator program written in C Language. It Performs addition, subtraction, multiplication or division depending the input from user. This usage switch case statement. Let see the C Program # include <stdio.h> int main() { char operator; double firstNumber,secondNumber; printf("Enter an operator (+, -, *,): "); scanf("%c",…
    Tags: program, language, learn, write
  • 48
    Snake Game is mini project  in a C language. It is console application without graphic library that's why it is more interesting. This game is perfect without any error and better user interface. It is complied in code block using c language. Here goes a source code you can copy and…
    Tags: program, write, language, learn
  • 45
    The if statement can take any of the following forms: if ( condition ) do this ; if ( condition ) { do this ; and this ; } if ( condition ) do this ; else do this ; if ( condition ) { do this ; and this…
    Tags: learn, program, write
  • 44
    Let's have an example to understand else if clause : /* else if ladder demo */ main( ) { int m1, m2, m3, m4, m5, per ; per = ( m1+ m2 + m3 + m4+ m5 ) / per ; if ( per >= 60 ) printf ( "First…
    Tags: program, learn, write

Leave a Reply

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

%d bloggers like this: