Exercise 1

Write a program to do the following:

(A) Ask the user to enter 5 characters and store these in 5 char variables named c1, c2, c3, c4, c5.

(B) Perform a cyclic exchange of values stored in the 5 variables:

c1 must hold the value given by the user and initially stored in c2,
c2 must hold the value given by the user and initially stored in c3,
c3 must hold the value given by the user and initially stored in c4,
c4 must hold the value given by the user and initially stored in c5,
and c5 must hold the value given by the user and initially stored in c1.

(C) Print the values of the variables once the exchange is done.

Exercise 2

Write a program which computes the areas of rectangles and circles. In particular:

(A) The first part of the program asks the user to enter two floating-point numbers, which are stored in variables L and W. Then, it computes and prints the area of a rectangle of length L and width W. Recall that the area of such rectangle is equal to L * W.

(B) The second part of the program asks the user to enter one floating-point number, which is stored in the variables D. Then, it computes and prints the area of a circle with diameter D. Recall that the area of a circle is PI * R2, where PI = 3.14159 and R is the radius of the circle which is half of the diameter.

Exercise 3

Write a program which is able to solve quadratic equation ax2 + bx + c = 0. In particular, the program asks the user to enter the parameters a, b, and c. Then, it computes the discriminant D = b2 - 4ac and the two solutions (-b + sqrt(D)) / 2a and (-b - sqrt(D)) / 2, which are printed.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.