AnkitWebLogic

Ans 2.1 Write a C Program to Input year and find it is leap year or not 1

#include<stdio.h>
int main()
{
    int y;
    printf("Enter year:");
    scanf("%d",&y);
    if(y%4==0)
    {
        printf("Year is Leap Year");
    }
    else
    {
        printf("Year is NOT a Leap Year");
    }
    return 0;
}
Run 1:
Enter year: 2023
Year is Not a Leap Year

Run 2:
Enter year: 2024
Year is Leap Year

Run 3:
Enter year: 2100
Year is Leap Year

Ans 2.2 Write a C Program to Input year and find it is leap year or not. 1

#include<stdio.h>
int main()
{
    int y;
    printf("Enter year:");
    scanf("%d",&y);
    //1. If the year is divisible by 4 and not divisible by 100, or
    //2. If the year is divisible by 400.
    if((y%4==0 && y%100!=0)||(y%400==0))
    {
        printf("Year is Leap Year");
    }
    else
    {
        printf("Year is NOT a Leap Year");
    }
    return 0;
}
Run 1:
Enter year: 2100
Year is Not a Leap Year

Run 2:
Enter year: 2000
Year is Leap Year