recent posts

Leap year program in C | C programming


Hi, I'm Golam Rabbani. Today I will discuss about Leap year program in C.
Greetings! How are you all? Hope everyone is well.
If you unknown about leap year. Please read Leap year article at Wikipedia.
Question 1: C program to check leap year.
#include<stdio.h>
int main(){
    int year;
    printf("Enter year: ");
    scanf("%d", &year);
    if(year%400==0){
        printf("%d is a leap year.", year);
    }
    else if(year%100==0){
        printf("%d is a not leap year.", year);
    }
    else if(year%4==0){
        printf("%d is a leap year.", year);
    }
    else{
        printf("%d is a not leap year.", year);
    }
    return 0;
}
Output:



Question 2: C program to check leap year using logical operator:
#include<stdio.h>
int main(){
    int year;
    printf("Enter year: ");
    scanf("%d", &year);
    if(((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)){
      printf("%d is a leap year", year);
    }
    else{
      printf("%d is not a leap year", year);
    }
    return 0;
}

Thanks to everyone.
Leap year program in C | C programming Leap year program in C | C programming Reviewed by Golam Rabbani on November 22, 2018 Rating: 5

No comments:

top navigation

Powered by Blogger.