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 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;
}

                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.