Check the year is leap or not program in swift

Check the year is leap or not program in swift programming language basics. This program is basic program in swift programs 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.

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

 

Output:

leap year

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.

What is leap year in swift

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.

How leap year is calculated in swift

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.