I dont understand what you wanted to do with your test no.4. why dont you just check our answer against the actual factorial, instead of hard coding (truncated) numbers?
testcase is nok:
Use if statement for test 4...
Faulty test case has been corrected. Those who have solved with respect to the rounded test case kindly solve the question again. It's a fairly simple one!
fail for x=120?! 'isequal(factorial(120),y)' gives me 0...
My solution works in Matlab, but fails the last test here.. :(
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 ?
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
fake solution, it works until there is a mistake in test 4
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!
Nice solution for that rounding problem.
There should be a test in the test suite to catch any uses of "factorial" in the submitted code, as is done here:
Also, is the convention here to round to five significant digits? If so, this should probably be noted in the problem statement.
Sum of diagonal of a square matrix
Find out missing number from a vector of 9 elements
Replace multiples of 5 with NaN
02 - Vector Variables 1
Flip the vector from right to left
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office