Home / Programs / Write a program in C that determines if a year is a leap year in different approach
Programming Example

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

👁 1,082 Views
💻 Practical Program
📘 Step by Step Learning
Write a program in C that determines if a year is a leap year in different approach

Program Code

#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

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

<b>Output 2:</b>
Enter the year to be tested:2012
It is a leap year.

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.