الانتقال إلى المحتوى

I Need A Hlpe To Create A Function That Takes A Single Input Number, And Returns The Factorial Of The Number


free2000000

Recommended Posts

1. Create and store a function that takes a single input number, and returns the factorial of the number.
The factorial of a number n is defined as 1 2 3 : : : (n ???? 1) n. If the input number is negative,
the function should give an error message, and return a value of ????1. Note that the factorial of zero is
1 by definition. You should implement the function in your own way, i.e., do not call a pre-defined
function in PL/SQL.

post-105730-1267908654_thumb.jpg

تم تعديل بواسطة free2000000
رابط هذا التعليق
شارك

Try this one:

CREATE OR REPLACE FUNCTION GET_FACTORIAL_NUMBER(n integer) RETURN integer IS
 x integer := 1;
 --i integer := 1; -- counter
BEGIN if n < 0 then
 dbms_output.put_line('Error entered negative Number!');
 x := -1;
else
 for i in 1..n loop
   x := i*x;
   --dbms_output.put_line(i||'!= '||x);
 end loop;
end if;
dbms_output.put_line(n||'!= '||x);
RETURN x;
END;

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية