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]
4 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]4 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]4 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
Why is an ISA unlikely to change between successive generations of microarchitectures
QveST [7]
Someone answer this because I need to know as well
\
4 0
3 years ago
A(n) ____ is an entry in a cell that contains text such as "2016 Sales" or "Travel Expenses."
slavikrds [6]

Answer:

B- label

Explanation:

A label is an entry such as a text within a cell that describes particular rows and columns. Labels are usually found at the top of the particular row/column they are identifying.

Hence, the texts "2016 Sales" and "Travel Expenses" are labels that identify cells such as the values of the sales in 2016 of a company and expenses spent on travel in a year of a family.

6 0
4 years ago
The template code provided is intended to check whether an integer entered by the user is outside of the range 20-29 (inclusive)
Pavlova-9 [17]

import java.util.Scanner;

public class JavaApplication60 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a number in the twenties");

       int num = scan.nextInt();

   if(num >= 30 || num <= 19){

       System.out.println("That's not in the twenties!");

       num = 25;

   }

   System.out.println("Your number is " + num);

   }

}

This is the complete code including the main class and main method. I hope this helps!

3 0
3 years ago
Threads in the ____ are idle, pending availability of a cpu.
slava [35]
Run queue. They can also be waiting on I/O.
7 0
4 years ago
Select the answer that best describes the ethical guideline followed in each scenario.
Montano1993 [528]
We need the scenario to solve this feel free to comment on this with your so scenarios and I will provide you with answers or just post another question
4 0
3 years ago
Other questions:
  • How can you recognize an unsecured wireless network?
    9·1 answer
  • To move down one paragraph, press the ____ key(s).
    15·1 answer
  • What does computer means?
    9·2 answers
  • In Windows applications, a ____ control is commonly used to perform an immediate action when clicked.a. text boxb. buttonc. wind
    7·1 answer
  • What is related to Gamut in Adobe illustrator?
    8·1 answer
  • What is the difference between a switch and a hub?
    8·1 answer
  • In the following code, use a lock to protect any data that might need protecting. Keep your critical sections as small as possib
    8·1 answer
  • Animations<br> Animations are !<br> Blank which can be Applied to blank in a presentation?
    7·1 answer
  • When a file is used by a program, there are three steps that must be taken:
    7·1 answer
  • In which cipher method are values rearranged within a block to create the ciphertext?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!