Leap year checking program in c | tamil | #CS8261 C PROGRAMMING LABORATORY

preview_player
Показать описание
CS8261 C PROGRAMMING LABORATORY

Leap year checking
Write a program to find whether the given year is leap year or Not? (Hint: not every centurion
year is a leap. For example 1700, 1800 and 1900 is not a leap year)

AIM
To write a C Program to find whether the given year is leap year or Not .


ALGORITHM
1. Start
2. Declare variables
3. Read the Input .
4. Take a year as input and store it in the variable year.
5. Using if,else statements to,
a) Check whether a given year is divisible by 400.
b) Check whether a given year is divisible by 100.
c) Check whether a given year is divisible by 4.
6. If the condition at step 5.a becomes true, then print the ouput as “It is a leap year”.
7. If the condition at step 5.b becomes true, then print the ouput as “It is not a leap
year”.
8. If the condition at step 5.c becomes true, then print the ouput as “It is a leap year”.
9. If neither of the condition becomes true, then the year is not a leap year and print
the same.
10. Display the output of the calculations .
11. Stop


PROGRAM
/*
* C program to find whether a given year is leap year or not
*/
void main(){
int year;
printf("Enter a year \n");
scanf("%d", &year);
if ((year % 400) == 0)
printf("%d is a leap year \n", year);
else if ((year % 100) == 0)
printf("%d is a not leap year \n", year);
else if ((year % 4) == 0)
printf("%d is a leap year \n", year);
else
printf("%d is not a leap year \n", year);
}


OUTPUT
Enter a year
2012
2012 is a leap year


Enter a year
2009
2009 is not a leap year


RESULT
Thus a C Program for Leap year checking was executed and the output was obtained.
Рекомендации по теме
join shbcf.ru