Thursday, 5 November 2015

PL SQL Program to check whether a number is perfect or not

declare
n number;
i number;
tot number;
begin
n:=&n;
tot:=0;
for i in 1..n/2
loop
if(n mod i=0) then
tot:= tot+i;
end if;
end loop;
if(n=tot)then
dbms_output.put_line('Perfect no');
else
dbms_output.put_line('Not a Perfect no');
end if;
end;

6 comments:

  1. FULL OF ERROR DUDE. WASTEπŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. declare
      n number;
      i number;
      tot number;
      begin
      n:= 496;
      tot:=0;
      for i in 1..n/2
      loop
      if(n mod i=0) then
      tot:= tot+i;
      end if;
      end loop;
      if(n=tot)then
      dbms_output.put_line('Perfect no');
      else
      dbms_output.put_line('Not a Perfect no');
      end if;
      end;

      Delete
  2. DECLARE
    n number(3):=8;
    num1 number(1):=1;
    sumn number(4):=0;
    BEGIN
    dbms_output.put_line('Check for Perfect Number');
    while (num1<n)
    loop
    if mod(n,num1)=0 then sumn:=sumn+num1;
    end if;
    num1:=num1+1;
    end loop;
    if sumn=n then dbms_output.put_line(n||' is Perfect Number');
    else dbms_output.put_line(n||' is not Perfect Number');
    end if;
    end;

    ReplyDelete
    Replies
    1. Check for the number you want, just put in your value in Line 2.

      Delete