Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Leap Year Program in C

Last Updated on April 25, 2023 by Prepbytes

Leap year program in C is important because it enables accurate calculations of time intervals, such as the number of days between two dates, and is used in many applications that deal with dates and times.

Leap Year

A leap year program in c contains an extra day, February 29th, which occurs once every four years to help synchronize the calendar year with the solar year. In C programming, checking for a leap year is important for many applications that deal with dates and times. A leap year is determined by a set of criteria that involve divisibility by 4, 100, and 400, as well as specific rules for different calendar systems. Checking for leap year can be implemented using if-else statements or other logical constructs. Accurately determining leap years is a fundamental aspect of time calculation and is crucial for many programs and applications

How to Calculate a Leap Year Program in C?

To find a leap year program in c you only need to enter a few mathematical conditions with the aid of the If statement in the program code to determine if a year is a leap year or not. The following criteria must be met to determine whether a particular year is a leap year or not:

• The entering year must divide evenly by four but not by 100.
• The year entered must divide evenly by 400.

To differentiate between leap years and century years, utilize the second condition. The years ending in ’00 are known as century years, examples are 1300, 1500, 1400, and so on. Only when a century year is equally divisible by 400 is it recognized as a leap year? For instance, since 1200, 1600, and 2000 are all precisely divided by 400, they are all century leap years. By following the above procedure we can easily find the leap year program in C.

Flow Diagram for a Leap Year Program in C

Here,is the flowchart for a leap year program in c:

Algorithm for Leap Year Program in C

Here, is the algorithm for the leap year program in C:

1. Declare and initialize the year variable.
2. If the year is divisible by 4, go to step 3. Otherwise, go to step 7.
3. If the year is divisible by 100, go to step 4. Otherwise, go to step 5.
4. If the year is divisible by 400, go to step 5. Otherwise, go to step 7.
5. The year is a leap year.
6. Output a message indicating that the year is a leap year.
7. The year is not a leap year.
8. Output a message indicating that the year is not a leap year.

Pseudo Code for Leap Year Program in C

Here, is the pseudo-code for the leap year program in c:

``````if (year is not divisible by 4) then it is a common 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 common year
else it is a leap year``````

Program to Find Leap Year Program in C

In the leap year program in c example, the user should enter a year and determine whether or not it was a leap year. But in this case, we’ll create a leap year program in C that will prompt the user for a range and print out all the leap years that fall within that range.

```#include <stdio.h>
int main()
{
int start_Year, end_Year, i;
printf("Enter the starting year of the range: ");
scanf("%d",&start_Year);
printf("Enter the last year of the range: ");
scanf("%d",&end_Year);
//the given range
printf("Leap Years between %d and %d are: \n", start_Year, end_Year);
for (i= start_Year; i<= end_Year; i++)
{
if (((i % 4 == 0) && (i % 100!= 0)) || (i % 400 == 0))
{
printf("%d \n", i);
}
}
return 0;
}
```

Conclusion
In conclusion, Checking for leap year program in c can be implemented using if-else statements or other logical constructs, and it is important to consider the specific rules and criteria for leap years in different calendar systems.