C Tutorial

This c program is used to find a year is leap year or not.

Year is leap year if divided by 400 or divided by 4 and not by 100.

if (year is not divisible by 4) then (it is a not leap year) else if (year is not divisible by 100) then (it is a leap year) else if (year is not divisible by 400) then (it is a not leap year) else (it is a leap year)

#include<stdio.h> void main() { int year; printf("Enter year: "); scanf("%d", &year); if (year%4 != 0) printf("%d is a not leap year.\n", year); else if (year%100 != 0) printf("%d is a leap year.\n", year); else if (year%400 != 0) printf("%d is a not leap year.\n", year); else // Not divisible by 4 and 100 or 400 e.g. 2017, 2018 printf("%d is a leap year.\n", year); }Output:

$ cc is_leap_year.c $ ./a.out Enter year: 2000 2000 is a leap year. $ ./a.out Enter year: 2017 2017 is not a leap year. $ ./a.out Enter year: 2016 2016 is a leap year.

C Program Examples

C Tutorial

Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page

^