Write a program in C that determines if a year is a leap year in different approach

C Programming Language Decision Making of C Language (Article) Decision Making of C Language (Program)

942

Program:

#include<stdio.h>
int main()
{
	int year, rem_4,rem_100,rem_400;
	printf("Enter the year to be tested:");
	scanf("%d", &year);
	rem_4 = year % 4;
	rem_100 = year % 100;
	rem_400 = year % 400;
	if( (rem_4 == 0 && rem_100 != 0) || rem_400 == 0)
		printf("It is a leap year.\n");
	else
		printf("It is not a leap year.\n");
		
		
    getch();		
	return 0;
}

Output:

Output 1:
Enter the year to be tested:2100
It is not a leap year.

Output 2:
Enter the year to be tested:2012
It is a leap year.

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.