C Program to check whether leap year or not with Algorithm
15-09-2016
This is the C program code and algorithm for checking whether the given year is a leap year or not.
Aim:
Write a C program to check whether the given year is a leap year or not.
Algorithm:
Step 1: Start Step 2: Read year year Step 3: if year mod 400 is 0, print the year is a leap year & go to step 7. Step 4: if year mod 100 is 0, print the year is not a leap year & go to step 7. Step 5: if year mod 4 is 0, print the year is a leap year & go to step 7. Step 6: print the year is not a leap year. Step 7: Stop
Program code
#include<stdio.h> #include<conio.h> void main( ) { clrscr( ) int year; printf("Enter the year: "); scanf("%d",&year); if(year%400==0) printf("The year is a leap year"); else if(year%100==0) printf("The year is not a leap year"); else if(year%4==0) printf("The year is a leap year"); else printf("The year is not a leap year"); getch( ); }
Output
Enter the year : 2012 The year is a leap year