Which of the following represents the factorial function?

A. Function Numeric unKnown(Numeric num)
   // Call function recursively until reaching 0 or 1
   If num == 0 Or num == 1 Then
      Return num
   Else
      Return unKnown(num - 2) + unKnown(num - 1)
   End If
End Function
B. Function Numeric unKnown(Numeric num)
   // Base case returns 1
   If (num == 1) Then
      Return 1
   Else
      Return (num * num) + unKnown(num - 1)
   End If
End Function
C. Function Numeric unKnown(Numeric num)
   // Declare variables
   Declare Numeric fact = 1
   Declare Numeric index // loop index
  
   // Loop
   For index = num to 1 Step -1
      fact = fact * index
   End For
   Return fact
End Function
D. Module unKnown(Integer n, sourcePeg, targetPeg, sparePeg)
   If (n > 0) Then
      moveDiscs(n - 1, sourcePeg, sparePeg, targetPeg)
   // Move disc from sourcePeg to targetPeg
      moveDiscs(n - 1, sparePeg, targetPeg, sourcePeg)
   End If
End Module


Answer: C

Computer Science & Information Technology

You might also like to view...

An organization's main assets consist of intellectual property rather than plants, buildings, or expensive computer hardware.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

PowerPoint's ____________________ feature allows you to trim the beginning and end of your clip.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Declare and create a multidimensional array to hold the first and last names of 10 people.

What will be an ideal response?

Computer Science & Information Technology

What is the output of the following code?

``` string s("abcdefg"); cout << s.substr(1, 3); ``` a. a b. bcd c. c d. abc

Computer Science & Information Technology