Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Sunday 25 March 2018

Prime PLSQL

This program will print prime numbers in the given range.
the range is given by the user.     
 


   DECLARE 
   i number(3); 
   j number(3); 
   num1 number :=&enter_range;
BEGIN 
   i := 2; 
   LOOP 
      j:= 2; 
      LOOP 
         exit WHEN ((mod(i, j) = 0) or (j = i)); 
         j := j +1; 
      END LOOP; 
   IF (j = i ) THEN 
      dbms_output.put_line(i || ' is prime'); 
   END IF; 
   i := i + 1; 
   exit WHEN i = num1; 
   END LOOP; 
END; 

No comments:

Post a Comment