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
Which of these is outside the scope of an art director's responsibility?
Morgarella [4.7K]

Answer: telling the animators that an entire scene must be reworked

Explanation:

4 0
2 years ago
Read 2 more answers
Which loan type requires you to make loan payments while you’re attending school?
tigry1 [53]
Direct Subsidized Loans I believe
7 0
3 years ago
An element in a web page that connects to a different location in the same page or a different page is a _____.
Softa [21]
I believe it would be the anchor element.

<a href="#"></a>

Correct me if I'm wrong.
3 0
3 years ago
anyone got a class named computer literacy? or sum similar to using Microsoft programs? i need a lotttt of help, im 3 units behi
seropon [69]

Answer:

I use google docs

Explanation:

I am in 6th grade but i am in expert in computers.

6 0
3 years ago
Read 2 more answers
Photo editing software, desktop publishing, email and word processing software is most likely to be used by:
FrozenT [24]

Answer:

c) mass media personnel

Explanation:

A software can be defined as a set of executable instructions (codes) or collection of data that is used typically to instruct a computer how to perform a specific task and to solve a particular problem.

Basically, softwares are categorized into two (2) main categories and these are;

I. System softwares.

II. Utility softwares.

Photo editing software, desktop publishing, email and word processing software is most likely to be used by a mass media personnel because he or she deals with the creation of various documents such as images, texts, multimedia files etc.

4 0
2 years ago
Other questions:
  • Write a function, factors, that takes an integer n, and returns a list of values that are the positive divisors of n. Note: 0 is
    13·1 answer
  • What makes Group Policy such a powerful tool is its ability to enable security administrators to:_________.
    8·1 answer
  • What term best describes the way the dns name space is organized?
    9·1 answer
  • T F Changes to a function parameter always affect the original argument as well.
    15·1 answer
  • This is a program that calculates information about orders of shirts and pants. All orders have a quantity and a color. Write a
    7·1 answer
  • Describe how the presence or absence of balance can affect a visitor’s perceptions of a Web page.
    7·1 answer
  • What is the orbit? Define
    12·1 answer
  • Fill in the blanks to complete a summary of this part of the passage. For the power of Patents
    6·2 answers
  • What is the correct way to write h1 tag
    12·1 answer
  • What is the process of smaw welding​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!