Pages

Powered By Blogger

Friday, 19 July 2013

FOR

P14. WRITE A PROGRAM TO PRINT THE MULTIPLICATION TABLE OF A
GIVEN NO:

SQL> Declare
r number;
no number;
Begin
no:=&NO;
r := &Range;
FOR I IN 1..r LOOP
dbms_output.put_line(no||' X '|| i || ' = ' ||i*no);
end loop;
end;
/

Enter value for no: 5
old 5: no:=&NO;
new 5: no:=5;

Enter value for range: 5
old 6: r := &Range;
new 6: r := 5;
5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
PL/SQL procedure successfully completed.


P15. WRITE A PROGRAM TO GENERATE EVEN NUMBERS FROM GIVEN RANGE (1 TO N),
AND FIND ITS SUM.


SQL> declare
i number(5);
n number(5);
v number(5);
s number(5):=0;
Begin
n := &Range;
for i in 1 .. n/2 loop
v := i*2;
s := s+v;
dbms_output.put_line(v);
end loop;
dbms_output.put_line('The sum of Even Numbers from 1 to '||n||' = ' ||s);
end;
/

Enter value for range: 10
old 7: n := &Range;
new 7: n := 10;
2
4
6
8
10
The sum of Even Numbers from 1 to 10 = 30
PL/SQL procedure successfully completed.


P16. WRITE A PROGRAM TO GENERATE FIRST 10 TERMS OF THE
FIBONACCI SERIES.


SQL> declare
a number:= 0 ;
b number:= 1;
c number;
begin
dbms_output.put('The series : ');
dbms_output.put(a||' '||b||' ');
for i in 3..10 loop
c := a + b;
dbms_output.put(c||' ');
a := b;
b := c;
end loop;
dbms_output.put_line(' ');
end;
/

The series : 0 1 1 2 3 5 8 13 21 34
PL/SQL procedure successfully completed.


P17.WRITE A PROGRAM TO FIND THE FACTORIAL OF A NUMBER.

Declare
n number(2);
i number(2);
f number(5):=1;
Begin
n :=&n;
for i in 1..n loop
f := f * i;
end loop;
dbms_output.put_line(' The factorial value = '||f);
end;

Enter value for n: 5
old 6: n:=&n;
new 6: n:=5;
The factorial value = 120


DOWNLOAD FOR.pdf

No comments:

Post a Comment