Question: Write a program that takes a year as the input from stdin and uses the modulus operator to determine if the year is a leap
Write a program that takes a year as the input from stdin and uses the modulus operator to determine if the year is a leap year or not. Print the result to the screen.
Here is the algorithm to check if a year is a leap year or not:
if year is not divisible by then it is a common year
else if year is not divisible by then it is a leap year
else if year is not divisible by then it is a common year
else it is a leap year
Here is what I have so far:
#include
int mainvoid
int year;
char c;
printfEnter a year: ;
use scanf to accept user input
check that expected data type was included in the user input
check that nothing else after the valid user input was included
use while loop to iterate forever until valid inout is received
whilescanfd &yearc getchar
&& c EOF
printfERROR: Invalid input. Please enter new value: ;
while c getchar
&& c EOF; flush input buffer before next scanf
TO DO: determine if input year is a leap year
ifyear
printfd is not a leap year.
;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
