0% found this document useful (0 votes)
27 views9 pages

Spiral 2

The document contains descriptions and PL/SQL code for several programs that perform different tasks: checking if a number is odd or even, positive or negative, calculating the factorial of a number, generating a multiplication table, displaying a range of numbers, checking if a number is prime, checking if a number is an Armstrong number, and generating the Fibonacci series. For each program, it provides the aim, algorithm, and PL/SQL code to implement the logic.

Uploaded by

Aparna Aparna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

Spiral 2

The document contains descriptions and PL/SQL code for several programs that perform different tasks: checking if a number is odd or even, positive or negative, calculating the factorial of a number, generating a multiplication table, displaying a range of numbers, checking if a number is prime, checking if a number is an Armstrong number, and generating the Fibonacci series. For each program, it provides the aim, algorithm, and PL/SQL code to implement the logic.

Uploaded by

Aparna Aparna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PL/SQL PROGRAMS

TO IFND THE GIVEN NUMBER IS ODD OR EVEN

Aim:

To write a PL/SQL program for the given number is odd or even .

Algorithm:

1. Start the program


2. Declare the necessary variables
3. Check if the number is modulo 2 , remainder is zero
4. Print the given number is even
5. Else the given number is odd
6. Stop the program

Program:

declare

n number:=&n;

begin

if mod (n,2)=0

then

dbms_output.put_line('number is Even');

else

dbms_output.put_line('number is Odd');

end if;

end;

/
POSITIVE OR NEGATIVE

Aim:

To write a PL/SQL program for the given number is positive or negative.

Algorithm:

1. Start the program


2. Input a number from the user.
3. If number is less than zero ,then it is a negative integer.
4. Else if number is greater than zero ,then it is a positive integer.
5. Else , the number is equal to zero.
6. Stop the program

Program:

declare

num1 number := &get_num;

Begin

If num1<0 then

dbms_output.put_line('the number '||num1||'is a negative number');

elsif num1 =0 then

dbms_output.put_line('the number '||num1||'is equal to zero');

else

dbms_output.put_line('the number '||num1||'is a postive number');

end if;

end;

/
FACTORIAL NUMBER

Aim:

To write a PL/SQL program for calculate factorial of a given number.

Algorithm:

1. Start the program


2. Declare variable n, fact I
3. Read number from user
4. Initialize variable fact=1 and I =1
5. Repeat Until I <=number
6. Fact=fact * I
7. I=i+1
8. Print fact
9. Stop the program

Program:

Declare

n number ;

fac number:=1;

I number;

Begin

N:=&n;

For I in 1..n

Loop

Fac:=fac * i

Endloop;

dbms_output.put_line(‘factorial=’||fac);

end;

OUTPUT:
MULTIPLICATION TABLE

Aim:

To write a PL/SQL program for describe the multiplication table.

Algorithm:

1. Start the program


2. Declare variable necessary variable.
3. Input n , the number for which multiplication table is to be printed.
4. For i= 1 to 10
5. Print x=n* i
6. End for
7. Stop the program.

Program:

declare

n number ;

I number;

begin

n:=&n;

for I in 1..10

Loop

dbms_output.put_line(‘n||’X’||i||;=’||n*i);

end loop;

end;

OUTPUT:
DISPLAYING N NUMBERS

Aim:

To write a PL/SQL program for display ‘N’ numbers.

Algorithm:

1. Start the program .


2. Declare the necessary variables.
3. Read the value of n and design i=1.
4. Repeat step 5&6 until i=num reach .
5. Print i
6. Compute i=i+1
7. Stop the program .

Program:

declare

n number:=&first _n_number;

begin

dbms_output.put_line(‘the first ‘||n||’numbers are:’);

for I in 1..n loop

dbms_output.put(i||’ ‘);

end loop;

dbms_output.new_line;

end;

OUTPUT:
PRIME NUMBER OR NOT

Aim:

To write a PL/SQL progrsm for given number is prime or not.

Algorithm:

1. Start the program


2. Read number n
3. Set flag =0
4. For i=2 to n-1
5. If n mod 1=0 then
6. Set flag =1 and break
7. Loop
8. If flag =0 then
9. Print ‘ The given number is prime’
10. Else
11. Print ‘ The given number is not prime ‘
12. Stop the program.

Program:

Declare

N number;

I number;

Flag number;

Begin i:=2;

Flag:=1;

N:=&n;

For I in 2..n/2

Loop

If mod(n,i)=0

Then

Flag :=0

Exit;

End if;

End loop;

If flag =1

Then

Dbms_output.put_line(‘prime’);
Else

Dbms_output.put_line(‘not prime’);

End if;

End;

OUTPUT:
ARMSTRONG NUMBER OR NOT

Aim:

To write a PL/SQL progrsm for given number is Armstrong or not.

Program:

Declare

N number(3);

S number(3):=0;

T number(3);

Begin

N:=&n;

T:=n;

While t>0 loop

S:=s+power((t mod 10),3);

T:=trunc(t/10);

End loop;

If(s=n) then

Dbms_output.put_line(‘the given number ‘|| n|| ‘ is an Armstrong numbet’);

Else

Dbms_output.put_line(‘the given number ‘|| n|| ‘ is not an Armstrong numbet’);

End if;

End;

OUTPUT:
FIBONACCI SERIES

Program:

Declare

A number:=0

B number:=1;

Temp number;

N number:=&n;

I number;

Begin

Dbms_output.put_line(‘fibonacci series is:’);

Dbms_output.put_line(a);

Dbms_output.put_line(b);

For I in 3..n

Loop

Temp:=a+b;

A:=b;

B:=temp;

Dbms_output.put_line(temp);

End loop;

End;

OUTPUT:

You might also like