StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #11 (U2): Leap Year Checker
Download
  1. C Programming
  2. C Programming Practice
Program #10 (U1): Absolute Value (no library) : Program #12 (U2): Grade Calculator from Percentage
C Programming Practice

Task: Read a year and apply the rules: divisible by 400 → leap, divisible by 100 → not leap, divisible by 4 → leap, else not. Print the correct verdict.

 
/* 

  Program: Leap Year Checker (U2)

  Logic: divisible by 400 → leap; else if divisible by 100 → not leap;

         else if divisible by 4 → leap; else not leap.

*/

 
#include <stdio.h>

 
int main(void) {

    int year;

 
    printf("Enter year: ");

    if (scanf("%d", &year) != 1) {

        printf("Invalid input. Please enter an integer.

");

        return 0;

    }

 
    if (year < 0) {

        printf("Year must be non-negative.

");

        return 0;

    }

 
    /* Apply leap year rules */

    if (year % 400 == 0) {

        printf("%d is a leap year.

", year);

    } else if (year % 100 == 0) {

        printf("%d is not a leap year.

", year);

    } else if (year % 4 == 0) {

        printf("%d is a leap year.

", year);

    } else {

        printf("%d is not a leap year.

", year);

    }

 
    /* Examples:

       2000 -> leap

       1900 -> not leap

       2024 -> leap

       2023 -> not leap

    */

 
    return 0;

}

 

 

Program #10 (U1): Absolute Value (no library) Program #12 (U2): Grade Calculator from Percentage
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website