Ask Question
31 August, 13:35

Below is a recursive implementation of the factorial function. For what value of n will this function not produce the desired result? What will the function do in that case? public static int factorial (int n) { if (n = = 0) return 1; else return n * factorial (n-1); }

+2
Answers (1)
  1. 31 August, 16:09
    0
    Check the explanation

    Explanation:

    Here the data type we are making use of is int. Now when this function is being called for finding factorial of 13 or numbers that are greater than 13 then the function is expected to shows error and the desired result will not be produced.

    Reason for this problem is- - range of int dat type is - 2,147,483,648 to 2,147,483,647. Now factorial of 12 is 47,90,01,600 which is less than 2,147,483,647. But factorial of 13 is 6,22,70,20,800‬ which is greater than 2,147,483,647 which means int data type can not hold such large variable. That's why it will not give desired result for value of n greater than 12.

    Now you might just want to ask that what will function do in that case - the afct ins that different languages do different things in case of overflows. Some languages just say that data type can not handle. take for instance, when it comes to java warning about overflow is not there. And during overflow there it will show negative numbers.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Below is a recursive implementation of the factorial function. For what value of n will this function not produce the desired result? What ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers