# EXERCISES

1. Write a program which simply prints out: 6.23e+00 2. Write a complete C program to prompt a user for input the quantity of each items, receive the input, do a calculation and print the input and the answer on the screen based on table item below. Item Book Pencil Multifunction paper Price / Item RM 12.50 RM 0.80 RM 10.50

Then modify the program to add another calculation and display the new result.

3. Write a function distance that calculates the distance between two points (x1,y1) and (x2,y2). All number and return values should be of type float. 4. Write a function multiply that accept 2 integers and returns the multiplication of those two integers. 5. Write a program that inputs a series of integers and passes them one at a time to function even, which uses the remainder operator to determine if an integer is even. The function should take an integer argument and return 1 if the integer is even and 0 otherwise. 6. Write a program that accepts 3 floating point numbers then pass these numbers to a function called smallest that later return the smallest value of the three floating point numbers. 7. Write a main program that calculates total of three scores and this calculation must be done in a separate function called total_score(). The main program should read three(3) scores and calls the function total_score(). Then the average of these three scores is calculated. If the average is > 40, then the status PASS is displayed. The sample output is as follows: Please enter your name: Norashikin Please enter the first score: 90.0 Please enter the second score: 60.0 Please enter the third score: 30.0

Name : Norashikin Total = 180.0 Average = 60.0 Status = Pass

8. Rewrite the following program using a user-defined function. #include<stdio.h> main () { int num; printf("Enter an integer or 999:"); scanf("%d",&num); do { printf("Number is: %d\n",num); printf("Enter an integer or 999:"); scanf("%d",&num); } while (num != 999); /* end_do_while */ } 9. Write program that calls another function, named message. Ask the users for their annual income in the main program. Pass the value of income from main program to the message function where this function will print a congratulatory message if the user makes more than RM50,000 a year or an encouragement message if the user makes less.