If you are an Objective C developer, who is going to make a calender type or something similar applications, then sometimes you may need to find out whether a year is leap year or not. You can use the following function to check whether a year is leap year or not.
Just pass the year to be checked (yearPassed) as an integer value to the following function. Then the function will check for leap year and it will return either 0 or 1 according to the conditions. If it returns 0, then the year is not a leap year. If it returns 1, then the year you passed to the function is a leap year.
Function syntax:
-(int)leapYearCheck:(int )yearPassed{
int isLeapYear = 0;
int yearTocheck = yearPassed;
if (yearTocheck%400 ==0) {
isLeapYear = 1;
}else if (yearTocheck%100 ==0){
isLeapYear = 0;
}else if (yearTocheck%4 ==0){
isLeapYear = 1;
}else if(yearTocheck%4 != 0){
isLeapYear = 0;
}
return isLeapYear;
}
Just pass the year to be checked (yearPassed) as an integer value to the following function. Then the function will check for leap year and it will return either 0 or 1 according to the conditions. If it returns 0, then the year is not a leap year. If it returns 1, then the year you passed to the function is a leap year.
Function syntax:
-(int)leapYearCheck:(int )yearPassed{
int isLeapYear = 0;
int yearTocheck = yearPassed;
if (yearTocheck%400 ==0) {
isLeapYear = 1;
}else if (yearTocheck%100 ==0){
isLeapYear = 0;
}else if (yearTocheck%4 ==0){
isLeapYear = 1;
}else if(yearTocheck%4 != 0){
isLeapYear = 0;
}
return isLeapYear;
}
No comments:
Post a Comment