Tech Unleashed

Wohoo!! We're on YouTube

Tuesday, 25 January 2022

C program for "Any year is input through the keyboard. Write a program to determine whether the year is leap year or not."

Problem: C program for "Any year is input through the keyboard. Write a program to determine whether the year is leap year or not."

Logic used :
  • Input the year.
  • Find the remainder using modulus operator with 4.
  • If the remainder is 0, year is leap year.
  • If the remainder is not equal to 0, year is not leap year.
Demo :
if(year % 4 ==0){
        printf("%d is a leap year.",year);
    }else{
        printf("%d is not a leap year.",year);
    }

C program :

// Program by Shyam Kanth

#include<stdio.h>

int main(){
    int year;
    printf("Enter the year : ");
    scanf("%d",&year);
    if(year % 4 ==0){
        printf("%d is a leap year.",year);
    }else{
        printf("%d is not a leap year.",year);
    }
    return 0;
}

Codes used :
  • #include < stdio.h > : Header file for input-output
  • int : Integer data type
  • year : Variable used 
  • printf : Function for displaying message
  • scanf : Function for taking input
  • if-else : Conditional statement
  • %d : Format specifier for integer type data
Do comments, if any doubt
Know about me : Shyam Kanth

No comments:

Post a Comment