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
Define a lambda function that accepts one argument (a list of strings) and returns a list of only the words that start with an '
Grace [21]

Answer:

  1. def Lambda(strList):
  2.    return list(filter(lambda s: (s.startswith("e")), strList))
  3. print(Lambda(["meaning", "cart", "engine", "egg"]))

Explanation:

The solution code is written in Python 3.

Lambda function is an anonymous function. It is a function without any name and it is started with keyword lambda. To write a lambda function to filter the string started with an 'e', we can write a lambda expression, s.startswith("e") that work on one input strList. If any word from strList started with letter "e", the word will be added into a list generated by filter function. At the end, the Lambda function will return the list of strings as output.

When we test the Lambda function using the sample string list (Line 4), we shall get ['engine', 'egg'] printed to terminal.

8 0
3 years ago
Difference between multi-national and global company​
trapecia [35]

A multinational corporation, or MNC, is a company which produces goods and services and has offices in several other countries while a global corporation or company is a company which also has trade relations with several other countries. ... MNCs have official headquarters while global companies do not.

5 0
2 years ago
Read 2 more answers
Sometimes, fourth-generation languages (4GLs) are called procedural languages
irakobra [83]
Hi!

In 1981, the term 4GL was actually used to refer to languages which were <em>non-procedural. </em>A procedural language does not possess <em>object-oriented </em>capabilities. 4GL's often times have OOP properties, so I believe the answer to this question is going to be <em>false. </em>=)
7 0
3 years ago
What do we call the two parts of lift that goes down a mine
Blababa [14]
The sheave wheel is a pulley wheel that sits above the mine shaft. The hoist cable passes over the sheave wheel and then down the shaft of the mine.
(copied from google)
4 0
3 years ago
Read 2 more answers
2) The CPU is made from a silicon<br>a) Steel<br>b) Chip<br>c) pendrive​
almond37 [142]

Answer:

Address buses are made up of a collection of wires connecting the CPU with main memory that is used to identify particular locations (addresses) in main memory. The width of the address bus (that is, the number of wires) determines how many unique memory locations can be addressed.

Explanation:

6 0
3 years ago
Other questions:
  • What isthe concept of packets, give example?
    9·1 answer
  • *asap* Name one of the similarities between Word and Excel.
    7·1 answer
  • Write a setInterval() function that increases the count by 1 and displays the new count in counterElement every 300 milliseconds
    12·1 answer
  • David uses Office Excel 2013 to calculate his average marks. He enters a formula in cell B5 to calculate the average based on th
    11·1 answer
  • What will the following loop display? 0 1 2 3 4 5 0 1 2 3 4 0 1 2 3 4 The loop will display numbers starting at 0, for infinity.
    8·1 answer
  • Which one of these are a valid IPv4 address? Check all that apply.
    9·1 answer
  • It is important to verify internet source because-------- choose that apply. A.the source should be written by real author. B.an
    6·2 answers
  • A computer has the following parameters Operation Frequency Cycles Arithmetic/Logical instructions 65% 1 Register load operation
    11·1 answer
  • In Java:
    15·1 answer
  • Easy<br> What is your favorite Anime<br> Mine is Attack On Titan at the moment
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!