Leap or Not in Swift

Leap or not in swift basic program for beginners. Here we have used the % method to print the value either leap year or not a leap year in swift program.

This will print the output if the condition executed properly. To declare a constant variable in Swift, we use the let keyword. A constant is a variable whose value cannot be modified once declared.

How Leap Year is Calculated in Swift

The if block will be run if the Boolean statement evaluates to true; else, the else block will be executed. 

Any non-zero and non-null values are assumed to be true in the c programming language, while zero and null values are assumed to be false.

A leap year is any year that is equally divisible by four: for example, 1988, 1992, and 1996. 

To avoid this blunder, the Gregorian calendar requires that a year that is equally divisible by 100 is also evenly divided by 400 to be a leap year. 

A leap year is a year that happens every four years. 

A leap year, unlike a regular year, has 366 days. 

We normally round the days to 365 and add one day to our calendar every four years to make up for the lost partial days. It’s a leap year this year.

Leap or Not in Swift and How to Calculate

The Earth’s orbit around the Sun lasts approximately 365.25 days, or one solar year. 

The number of days in a calendar year is usually rounded up to 365. 

To make up for the missed day, we add one day to our calendar every four years.

This year is a leap year. A leap year occurs every four years.

An extra day is added to the year. Instead of the usual 365 days, it has 366 days. 

In February, an extra day is added to the month, which now contains 29 days instead of the usual 28. 

Every four years, there are leap years. 

For instance, the year 1900 was not a leap year, but the year 2000 was.

let year = 1934
if year%4==0
{
print("leap year")
} 
else 
{
print("not leap year")
}

Output:

leap year

Compiler: Click Here