Starting from:

$30

COM1002 Lab 2 -Solved

Write a C program that computes the maximum, minimum, sum and average of 3 integers. This program reads 3 integers and a character that specifies the math opera9on (x for maximum, m for minimum, s for sum, a for average) from command prompt and prints the result of the opera9on. The input/output format is provided below.  

The output should be printed in integer format for x, m and s opera9ons; but in floa-ng point format for average (a) opera9on. Floa9ng points must be printed in 2 digits precision aDer the decimal point (See Hint below).

Input: <number 1>[space] <number 2>[space] <number 3>[space] <operaQon> 

Output: <computed value> 

Example 1: 

>15 3 28 m >3

Example 2: 

>20 32 4 s

>56

   

Example 3: 

>20 32 4 a

>18.67

Hint: %.2f format specifier prints 2 digit precision for floa9ng point numbers.

More products