InterviewSolution
Saved Bookmarks
| 1. |
Write a PL/SQL program using WHILE loop for calculating the average of the numbers entered by user. Stop the entry of numbers whenever the user enters the number 0. |
|
Answer» DECLARE n NUMBER; average NUMBER :=0 ; sum NUMBER :=0 ; count NUMBER :=0 ;BEGIN -- TAKE INPUT from user n := &input_number; WHILE(n<>0) LOOP -- Increment count to find total elements count := count+1; -- Sum of elements ENTERED sum := sum+n; -- Take input from user n := &input_number; END LOOP; -- Average calculation average := sum/count; DBMS_OUTPUT.PUT_LINE(‘Average of entered NUMBERS is ’||average);END; |
|