## Question

Objectives

• Gain experience with if, if else, and switch statements in C programs.

• Experience using % operator and true false logic.

Due Date is Tuesday 2/23 at 11:59 PM.

There will be a second control assignment using the switch statement Due Thursday 2/25.

Hints

This program will be MUCH easier if you design how to do the logic in your own words first. Do not even think about C until you understand the true false logic and the arithmetic needed to do it. Make sure you have a formula or a plan to calculate each case.

The program

The user types in two numbers to find if the first is evenly divisible by the second.

The program will output:

<first> is evenly divisible by <second>

Or

<first> is <value> too large to be evenly divisible by <second>. The closest number is <number>.

Or

<first> is <value> too small to be evenly divisible by <second>. The closest number is <number>.

Or

<first> is <value> off, in the middle from <lower number> or <larger number>

Examples:

User types 49 and 7.

49 is evenly divisible by 7.

User types 50 and 7.

50 is too large to be evenly divisible by 7. The closest number is 49.

User types 55 and 7.

55 is too small to be evenly divisible by 7. The closest number is 56.

User types 52 and 8.

52 is 4 off, in the middle from 48 or 56.P

Part II

Objectives:

• Exposure to using the C switch statement with breaks and without breaks.

The Program 2 Parts:

1. Ask the user to enter a year, a month and a day after 1600.

a. Print an error message if year is < 1600 or month is not 1 – 12 or day not 1 – correct number for that month.

b. If no error, print the day of the year.

Rules:

You must use an if statement for the year.

You must use a switch statement on the month to find the number of days in that month with break statements for each case.

You must use the # of days in that month to test is the day is correct.

Correctly calculate the # of days in February based on the year.

One and only one return or exit in main at the bottom last line.

You must use a variable to keep track of whether there is an error or not from one part of the program to the next.

Any right } that is more than 3 lines away from its { must have a comment explaining what it is the end of.

If ( a < b) {

Statement1;

Statement2;

Statement3;

Statement4;

} // end a < b

2. Use another switch statement with no break statements to find the day of the year. 2/1 is 31 days of January plus 1 in February for a total of 32.

So there are 2 (two) switch statements in the program.

Hints:

January 28 (1/28/16) is the 28th. Day of the year.

Exactly Which Years Are Leap Years?

We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary, day and we add it to the shortest month of the year, February.

In the Gregorian calendar three criteria must be taken into account to identify leap years:

- The year can be evenly divided by 4;

- If the year can be evenly divided by 100, it is NOT a leap year, unless;

- The year is also evenly divisible by 400. Then it is a leap year.

This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800,1900, 2100, 2200, 2300 and 2500 are NOT leap years.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>#include <stdlib.h>

int main(int argc, char** argv) {

int first, second;

int remainder;

double half;

printf("Enter 2 number: ");

scanf("%d %d", &first, &second);

remainder = first % second;

half = (double)second / 2.0;

if (remainder == 0) {

printf("%d is evenly divisible by %d\n", first, second);

} else if ((double)remainder < half) {

printf("%d is too large to be evenly divisible by %d. The closest number is %d.\n", first, second, first - remainder);...

By purchasing this solution you'll be able to access the following files:

Solution1.c and Solution2.c.