Sum and average of three numbers in PL/SQL
Prerequisite
Examples:
Input: a = 12, b = 15, c = 32 Output: sum = 59 avg = 19.66 Input: a = 34, b = 45, c = 11 Output: sum = 90 avg = 30
Approach
--To find sum and avg of three numbers DECLARE -- Assigning 12 into a a NUMBER := 12; -- Assigning 14 into b b NUMBER := 14; -- Assigning 20 into c c NUMBER := 20; -- Declare variable for sum -- Of Three number (a, b, c) sumOf3 NUMBER; -- Declare variable for average avgOf3 NUMBER; --Start Block BEGIN -- Assigning sum of a, b and c into sumOf3 sumOf3 := a + b + c; -- Assigning average of a, b and c into avgOf3 avgOf3 := sumOf3 / 3; --print Result sum of a, b, c number dbms_output.Put_line( 'Sum = ' ||sumOf3); --print Average sum of a, b, c number dbms_output.Put_line( 'Average = ' ||avgOf3); END ; --End Program |
Output:
Sum = 46 Average = 15.33
Contact Us