Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing this program in C language, (printf / scanf... not < > / system.print) Thank you. Write a program to ask the

I need help writing this program in C language, (printf / scanf... not <> / system.print) Thank you.

Write a program to ask the user to enter a year after 1582 (the current calendar, the Gregorian calendar, was introduced in October 1582). If the year entered is 1582 or before, inform the user and exit the program. Otherwise, display whether the year is a leap year or not.

A year is a leap year if the year can be evenly divisible by 4, but it is not a leap year is the year can also be evenly divisible by 100. But if the year can be evenly divisible by 400, then is it a leap year regardless. For example, the year 1900 is not a leap year, the year 2000 is a leap year, the year 2002 is not a leap year, and the year 2004 is a leap year.

Create a constant for the year 1582 and use the constant in the prompt, the validation condition, and the validation error message.

Hint: Use the Mod operator (%) to see if the year is evenly divisible by a number (if it is evenly divisible, the Mod operator will return a reminder of 0). You will need nested if statements or an if - else if - else if block to determine whether the year is a leap year, and another decision to determine whether to print "...is a leap year." or "...is not a leap year." , in addition to a decision for the validation for years less than 1583, for this program. I used a boolean variable to store whether the year was a leap year (true) or not (false).

Example Run #1: (bold type is what is entered by the user)

Enter a year (after 1582): 2000

The year 2000 is a leap year.

Example Run #2:

Enter a year (after 1582): 2002

The year 2002 is not a leap year.

Example Run #3:

Enter a year (after 1582): 1582 The year entered was not after 1582.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions