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
I just started game development using unity, I’m trying to control my sphere moving on a flat surface using the W,A,S,D keys, if
uysha [10]

Answer:

Explanation:

public class Controlador: MonoBehavior

{

// we declare velocity variable, we can change the value to get more speed

public float velocidad = 3f;

void Start()

{

 

}

void Update()

{

// with this condition we select the key for the movement.

// for example the left arrow or the letter "a"

  if (Input . GetKey(KeyCode . LeftArrow) |I Input . GetKey("a"))

  {

    transform . position += Vector3 . left * velocidad * Time . deltaTime;

  }

   if (Input . GetKey(KeyCode . RightArrow) |I Input . GetKey("d"))

  {

    transform . position += Vector3 . right * velocidad * Time . deltaTime;

  }

   if (Input . GetKey(KeyCode . UpArrow) |I Input . GetKey("w"))

  {

    transform . position += Vector3 . up * velocidad * Time . deltaTime;

  }

   if (Input . GetKey(KeyCode . DownArrow) |I Input . GetKey("s"))

  {

    transform . position += Vector3 . down * velocidad * Time . deltaTime;

  }

}

}

6 0
4 years ago
What Word features allow you to copy multiple paragraph formatting syles
PSYCHO15rus [73]
Format painter allows us to copy multiple fomatting styles at the same time from within a word document
5 0
3 years ago
My friend has a battery of 9000mah and loses 10 every day how many days well it take to go to zero
forsale [732]
I think it's 900 but I can't be sure.
8 0
3 years ago
Creating a call conversion in Google Ads and adding a phone snippet to a web page allows advertisers to use a Google forwarding
Marta_Voda [28]

Answer:

Call tracking system

Explanation:

It helps to measure total amount of visitors per month and based on the volume of visitors, it calculates how many phone numbers should be displayed to show a different number for each clique.

5 0
3 years ago
Which setting indents all but the first line of a paragraph by the selected length?
Phoenix [80]

Answer:

Hanging

Explanation:

5 0
3 years ago
Other questions:
  • Which of these statements is true? Steve Jobs invented the mouse as an input device. Bill Gates invented the mouse as an input d
    6·1 answer
  • You are holding a rock tied to a string, which is an example of a pendulum. identify and explain the proper term for each part o
    10·2 answers
  • Which software product release category is "generally feature complete and supposedly bug free, and ready for use by the communi
    7·1 answer
  • Hello, please help write code in C++. Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go nort
    12·1 answer
  • Normal wear and road conditions can take their toll on a car’s steering and suspension system, altering __________. A. wheel ali
    15·2 answers
  • Is 5g harmful to the body ?
    9·2 answers
  • A technician has just installed a video card in a PC. The video card is not working, althoughit was working fine on the test ben
    6·1 answer
  • What functions do these WLAN applications and tools perform on WLANs: airmonng, airodump-ng, aircrack-ng, and aireplay-ng
    10·1 answer
  • How do you change your name on brainly after you have made an account​
    5·1 answer
  • Explain the emerging trends in microcomputer technology in relation to size​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!