TOPIC 4 EXERCISE 1

Task 1 

Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is zero, positive or negative.




Task 2

Write a program that prompts the user to input three numbers. The program should then output the number in ascending order.







Task 3

Write a program that prompts the user to input an integer between 0 and 35. If number less than or equal to 9, the program should the number; otherwise, it should output A for 10, B for 11, C for 12, … , and Z for 35. (Hint: Use the cast operator (char) for numbers >= 10.)


Task 4

The cost of an international call from New York to New Delhi is calculated as follows: connection fee, $1.99; $2.00 for the first three minutes; and $0.45 for each additional minute. Write a program that prompts the user to input a number. The program should then output the number of minutes the call lasted and output the amount due. Format your output with two decimal places.



Task 5

Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.) Some sample output as follows: 

3 + 5 = 8

4 * 7 =28

6 / 0 Error! Division by zero is not allowed.






Comments

Popular posts from this blog

PROBLEM SOLVING EXERCISE