Fundamentals of Programming - 2

Homework 1

  1. Write a program that takes as input an integer "n" and outputs "good" if n is divisible by   2   but not by   3   and "bad" otherwise. (e.g. 8 and 10 are good, 7 and 12 are bad).


  2. Suppose Tom has "x" dollars deposited in a bank for "n" years. The bank gives him simple interest at the rate of 5% per annum for the first 5 years and 10% thereafter. To be specific,



    Write a program that takes the values x and n from the user (Tom) and outputs the interest earned. Assume that x is a real number and n is a positive integer. If Tom inputs a negative integer for n the program should say "Invalid input" and exit.


  3. Recall that the quadratic equation (ax2 + bx + c = 0) has 2 solutions given by :



    The equation has no solution in real numbers if (b2-4ac) < 0. Write a program that takes as input the values a,b,c from the user and outputs "No solution exists" if there is no real number satisfying the equation and outputs the 2 real valued solutions otherwise. (Don't forget to include the < cmath > library).