1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
xxTIMURxx [149]
3 years ago
10

In mathematics, the factorial of a positive integer n, denoted as n! , is the product of all positive integers less than or equa

l to n.
The factorial of n can be computed using the following rules.

Case I: If n is 1, then the factorial of n is 1.
Case II: If n is greater than 1, then the factorial of n is equal to n times the factorial of (n - 1).
The factorial method returns the factorial of n, as determined by case I and case II. Write the factorial method below. You are encouraged to implement this method recursively.

/** Precondition: n is between 1 and 12, inclusive.

* Returns the factorial of n, as described in part (a).

*/

public static int factorial(int n)
Computers and Technology
2 answers:
MrRa [10]3 years ago
6 0

Answer:

public static int factorial(int n) {

   

    if (n >= 1 && n <=12) {

           if (n==1)

               return 1;

           else

               return n * factorial(n-1);

    }

    else

        return -1;

}

Explanation:

Create a method called factorial that takes one parameter, n

Check if n is n is between 1 and 12. If it is between 1 and 12:

Check if it is 1. If it is 1, return 1. Otherwise, return n * function itself with parameter n-1.

If n is not between 1 and 12, return -1, indicating that the number is not in the required range.

For example:

n = 3  Is n==1, NO factorial(3) = n*factorial(2)

n = 2  Is n==1, NO factorial(2) = n*factorial(1)

n = 1  Is n==1, YES factorial(1) = 1.

Then factorial(2) = 2*1 = 2, factorial(3) = 3*2 = 6

Elis [28]3 years ago
4 0

Answer:

Explanation:

public static int factorial(int n){

if (n<=1){

return 1:

}else if (n>1 && n<=12){

return n * factorial(n - 1);

}

}

int  main() {

printf( "Enter a value :");

  scanf("%d", &n);

  printf("Factorial of %d is %d\n", n, factorial(n));

  return 0;

}

You might be interested in
Match the job task to the occupation that would perform it. 1. Research the causes and treatments of diseases physical scientist
Trava [24]

Answer:

1.Physical scientist

2.Life scientist

3.Electrical engineer

4.aerospace engineer

Explanation:

5 0
3 years ago
Why is it worth remembering “All people seem to need data processing”?
Rzqust [24]
The answer is .........C
3 0
3 years ago
Read 2 more answers
Which tab on the Table Tools contextual tab is used to control the style and formatting of the table as it relates to colors for
laila [671]

Answer: The answer would be the "Home Tab"

Explanation:

4 0
3 years ago
On a client/server network, which computer initiates the process of assigning an IP address through DHCP?
Vera_Pavlovna [14]

Answer:

The client

Explanation:

On a client/server network, THE CLIENT computer initiates the process of assigning an IP address through DHCP. This is because "The Client" computer will serve as the Domain controller in which other computers of the network can find. Hence, The Client computer initiates the process of assigning IP addresses through DHCP to achieve this.

Though, in some case. A user can manually assign the IP address to computer if it is not through DHCP

4 0
3 years ago
Put the steps in order to produce the output shown below. Assume the indenting will be correct in the program.
FromTheMoon [43]
For numb in [5,8]:
for numa in [2,3]:
print(str(numb) + str(numa))
3 0
2 years ago
Other questions:
  • Which of the following is a useful policy to minimize waste and mistakes?
    6·1 answer
  • Which of the following commands is more recommended while creating a bot?
    9·1 answer
  • It is important that data being imported from a text file into access are separated by a character, such as a comma, which defin
    8·1 answer
  • Write a program to read data from a file named problem 2. ext. This file has three exams data (floating point data) in three col
    11·1 answer
  • Write a program that lets the user enter a nonnegative integer then uses a loop to calculate the factorial of that number. Displ
    11·1 answer
  • How do i make spaces in python<br> To draw hello world
    15·1 answer
  • What is the ability for a system to respond to unexpected failures or system crashes as the backup system immediately and automa
    8·1 answer
  • CC stand for.....in the email platform?
    12·2 answers
  • What is the main circuit board inside the computer called?CD-ROMY
    12·1 answer
  • I am trying to sum up a set of data based on 2 criteria (needs to have "green" in column E, and "January 2020" in collum A). Col
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!