Lecture 6:  Conditionals

Activity:

 

 

1.  Write a C program that prompts the user to enter a number (of integer type) and prints the absolute value of this number.  For the purpose of this activity, please do not use the abs function in the math library.
(Hint:  You might want to describe the algorithm in English before writing any code.  When you have written the code, be sure to hand-trace the code with sample input values.)
 
 
 
 
 
 

2.  (Exercise 5 in chapter 4 of Hanly, Koffman)  Write a program that takes the x-y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies or the quadrant in which it is found.


Sample lines of output:

(-1.0, -2.5) is in quadrant III
(0.0, 4.8) is on the y axis