Program to check leap year
LEAP YEAR:
A leap year is a year that is divisible by 4, but not by 100, unless it is also divisible by 400. This means that years like 2024, 2020, and 2016 are leap years, but 2100 is not.
PROGRAM:
include <stdio.h>
int main()
{
int year;
printf("Enter the year: ");
scanf("%d",&year);
if((year%4==0 && year%100!=0) || year%400==0)
{
printf("%d is a leap year", year);
}
else
{
printf("%d is not a leap year", year);
}
return 0;
}
TIME COMPLEXITY:
The time complexity of this program is O(1) because the program only performs a fixed number of operations regardless of the input size. The if- else statement and the printf statements are executed once each, making the time complexity O(1).
SPACE COMPLEXITY:
The space complexity is O(1) because the program only uses a constant amount of memory to store the input year and a few variables.
}
Comments
Post a Comment