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
Whitepunk [10]
3 years ago
8

Write a function factorial() that takes a positive integer as a parameter and returns the factorial of that integer. The main fu

nction takes an integer n<=7, as input, and utilizes the factorial function to calculate the following series.
Computers and Technology
1 answer:
Elena-2011 [213]3 years ago
6 0

Answer:

The solution code is written in C++:

  1. #include <iostream>
  2. using namespace std;
  3. int factorial(int n){
  4.    if(n == 1){
  5.        return n;
  6.    }else{
  7.        return n * factorial(n-1);
  8.    }
  9. }
  10. int main()
  11. {
  12.    int n;
  13.    cout<<"Please enter a number <= 7 :";
  14.    cin>>n;
  15.    
  16.    if(n <= 7){
  17.        cout<<"Factorial is "<< factorial(n);
  18.    }else{
  19.        cout<<"Wrong input number.";
  20.    }
  21.    return 0;
  22. }

Explanation:

Firstly, create a function factorial with one input parameter (Line 1).

Next, create an if-else statement to check if input n is 1, just return the end (Line 6-7).

Otherwise, the function should return n multiplied by output of the recursive calling of the function itself (Line 8-9).

In the main program, create variable and prompt user to input number (Line 15 -17).

Next, do the input validation checking to ensure the input n must be equal or less than 7 then only call factorial function to calculate the factorial of n and display the answer (Line 19 - 20). Otherwise, the program shall just display error message.

You might be interested in
Someone wanna be in a meeting with me <br><br><br> Code: rrx-ofrw-ocj
ss7ja [257]

Answer:

Zoom¿ is ot in zoom cause am down

6 0
3 years ago
Read 2 more answers
Who plays pokemon shield or sword
schepotkina [342]

Answer: I haven’t played but i wanna

Explanation:

4 0
3 years ago
Read 2 more answers
What is a good principle to implement when you find yourself attempting to
Maurinko [17]

its less is more A

to much could make it really bad

5 0
4 years ago
A technician is installing a server using a two-channel RAID controller, using RAID1 for the first channel and RAID5 for the sec
Stolb23 [73]

Answer:

Two disks RAID 1 and four disks RAID 5.

Explanation:

The RAID level stands for Redundancy array of independent disk drive level. It is a process whereby disk storage like hard disk drive or solid state disk are connected in array to function in parallel to each other, to promote performance and reliability. The categories of raid level are 0, 1, 3, 5, 10 etc.

The RAID level 1 writes data on both main disk and mirror disk. It is more efficient with only two disk. The RAID 5 strips data across disk array and stores a parity check on them. It can hold 16 disks efficient and can be used in the two channel RAID to hold the remaining four disks.

5 0
3 years ago
And, Or, Not are examples of:
yanalaym [24]
Boolean operators it is
all the best
5 0
3 years ago
Other questions:
  • Design the below using an array// Sunrise Freight charges standard// per-pound shipping prices to the five states they serve// –
    6·1 answer
  • What can help establish the focus and organization it relies on?
    6·1 answer
  • Collaboration, listening, and negotiating are considered _____ skills.
    5·1 answer
  • Keyshia is preparing a report about the different tools that are used in a science laboratory. She wants to edit a picture of gl
    11·2 answers
  • In a 4-way 16-bit Multiplexor the selector is:________
    6·1 answer
  • Anyone good at graphics?
    14·1 answer
  • 15. It is the process of capturing data or translating information to recording format
    12·1 answer
  • . . ........Sad + sad= very sad
    7·2 answers
  • Give 5 characteristics of bad capacitor<br> give 5 characteristics of good capacitor
    10·1 answer
  • What are tasks performed by pascaline?​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!