MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply TodayCalculate the factorial of a non-negative integer without using the built in function **factorial**

58 correct solutions
191 incorrect solutions

Last solution submitted on Apr 18, 2016

1 player likes this problem

1 Comment

B. C.
on 5 Dec 2014

fail for x=120?! 'isequal(factorial(120),y)' gives me 0...

1 Comment

Neeraj Badamikar
on 5 May 2014

My solution works in Matlab, but fails the last test here.. :(

1 Comment

Swapnali Gujar
on 10 Aug 2013

I am trying to solve this problem and first 2 test cases are passed, but assertion is failing for last test case. I also used the format as 'short eng', here the y_correct is read by Matlab as '6.689500000000000e+198', but my program is calculating answer as '6.689502913449124e+198' for x = 120 and thats why its failing. Any suggestions ?

1 Comment

Ramy Mohamed
on 31 Jul 2013

There is something wrong with the last test; The number are truncated. y_correct should be 6.689502913449135e+198; while in the test it is given as 6.689500000000000e+198

1 Comment

Jan Orwat
on 26 Jul 2013

fake solution, it works until there is a mistake in test 4

1 Comment

Mohammed Manna
on 26 Jul 2013

I KNOW THIS SOLUTION IS CORRECT....STUPID IDE IS NOT ACCEPTING IT....YOU CAN RUN IT ON A STANDALONE MATLAB AND SEE IF IT WORKS!

1 player likes this solution

1 Comment

Tobias SchÃ¤fer
on 26 Jul 2013

Nice solution for that rounding problem.

1 Comment

Evan
on 25 Jul 2013

There should be a test in the test suite to catch any uses of "factorial" in the submitted code, as is done here:
http://www.mathworks.com/matlabcentral/cody/problems/498-find-the-kronecker-tensor-product-without-using-kron
Also, is the convention here to round to five significant digits? If so, this should probably be noted in the problem statement.

3 Comments