Home » RDBMS Server » Server Administration » prime number
prime number [message #373465] Wed, 18 April 2001 10:54 Go to next message
randy
Messages: 25
Registered: November 2000
Junior Member
Can anybody write a program to find out the prime number?
Re: prime number [message #373478 is a reply to message #373465] Wed, 18 April 2001 15:31 Go to previous messageGo to next message
Rajeev Mancheril
Messages: 4
Registered: April 2001
Junior Member
Hi,

Try out this.

Set n = 2
set prime = true
if input number > n+1
if input number MOD n = 0 or
input number MOD n+1 = 0 then
prime = false
endif
end if;
print prime;
Re: prime number [message #373488 is a reply to message #373465] Thu, 19 April 2001 04:07 Go to previous message
Thirumalai and Prakash
Messages: 23
Registered: March 2001
Junior Member
Hi Rajeev,
Here is the solution,

------------------------------
set serveroutput on
declare
n number := &input_number;
m number ;
output varchar(15) := ' Prime';
begin
m := sqrt(n);
for i in 2..m loop
if (mod(n,i) = 0) then
output := ' Not prime';
exit;
end if;
end loop;
dbms_output.put_line(n || output);
end;
/
-----------------------

Regards
S.Thirumalai
Previous Topic: Input truncated to x characters
Next Topic: SQL
Goto Forum:
  


Current Time: Mon Dec 23 10:33:59 CST 2024