Program:
FIND THE SUM AND AVERAGE OF ANY GIVEN NOS.
DECLARE
N1 NUMBER(2):=&N1;
N2 NUMBER(2):=&N2;
N3 NUMBER(2):=&N3;
S NUMBER(3);
A NUMBER(3);
BEGIN
S:=N1+N2+N3;
A:=S/3;
DBMS_OUTPUT.PUT_LINE('SUM='||S);
DBMS_OUTPUT.PUT_LINE('AVERAGE='||A);
END;
OUTPUT:
Enter value for n1: 10
old 2: N1 NUMBER(2):=&N1;
new 2: N1 NUMBER(2):=10;
Enter value for n2: 20
old 3: N2 NUMBER(2):=&N2;
new 3: N2 NUMBER(2):=20;
Enter value for n3: 30
old 4: N3 NUMBER(2):=&N3;
new 4: N3 NUMBER(2):=30;
SUM=60
AVERAGE=20
For practical:
DECLARE
-- Declare variables to store the given numbers and the sum num1 NUMBER; num2 NUMBER; sum NUMBER; avg NUMBER; BEGIN -- Get the input numbers from the user DBMS_OUTPUT.PUT_LINE('Enter first number:'); num1 := &num1; DBMS_OUTPUT.PUT_LINE('Enter second number:'); num2 := &num2;
-- Calculate the sum of the two numbers sum := num1 + num2;
-- Calculate the average of the two numbers avg := sum / 2;
-- Display the sum and average of the numbers DBMS_OUTPUT.PUT_LINE('Sum: ' || sum); DBMS_OUTPUT.PUT_LINE('Average: ' || avg); END;