Homework #4

Due Friday, May 15, 11:59 PM

Answer to each question should be in a separate file. The files should not be written to after the due date.
  1. [2 points] Write a program in which you declare three integer variables (X, Y, and Z), and does the following:

    (i) [0.5 points] first, takes the two integers X and Y as inputs from the user via scanf;

    (ii) [1 point] second, it uses a single line expression to compute the value of Z given by:
    Z = maximum of X and Y when: X > 0 and Y > 0.
    If either X or Y is not positive, Z = 1

    (iii) [0.5 points] Third, the program must print the following:
    The value of Z is equal to ?
    where "?" is replaced by the actual integer value of Z.


  2. [3 points] [See Exercises 22 & 23, Chapter 4, of the textbook] Write a program to solve a quadratic equation, a*X*X + b*X + c = 0. The values a, b, and c are floating point numbers, given by the user as inputs using scanf. X is the root of the quadratic equation, which needs to be calculated by your program. Your program must prompt the user for input as follows:
    a =
    b =
    c =
    Assume that a is non-zero. Your program should consider each of the three different cases:

    (i) square(b) - 4ac < 0,

    (ii) square(b) - 4ac == 0, and

    (iii) square(b) - 4ac > 0.

Back to Grading & Homeworks page