Exercises
Exercises
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.
Book RM 12.50
Pencil RM 0.80
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:
Total = 180.0
Average = 60.0
Status = Pass
#include<stdio.h>
main ()
int num;
scanf("%d",&num);
do
scanf("%d",&num);
/* 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.