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
Any file that contains data but not instructions for your computer is not considered software
DIA [1.3K]
True. 

But then again, partly false. A .deb file (Debian, Ubuntu Linux) contains data, but that data needs to be installed and marked executable to make the software.

But i would still say true.
5 0
3 years ago
Use the variables k and total to write a while loop that computes the sum of the squares of the first 50 counting numbers, and a
pshichka [43]
Int   k=0.total=0;
while(k++<50)
    total+=k*k;
    

5 0
4 years ago
If you are interested in joining the military, you can attend college _____. a. before serving b. during service c. after servic
Arturiano [62]

D .All the above.

Explanation:while in the military you can take online courses during service or you can can choose to do it before or after

6 0
4 years ago
Because some countries have poor traditional telephone services, companies and consumers have resorted to Group of answer choice
maw [93]

Answer:

a. leap frogging

Question:

Because some countries have poor traditional telephone services, companies and consumers have resorted to Group of answer choices leap frogging. express package services. satellite telephones. fiber-optic telephones. voice over internet protocol (VOIP) services.

3 0
3 years ago
After you divide the viewfinder appropriately you locate the subject? PLZ ANSWER MY TEST DO BY TONIGHT
Sloan [31]
The Answer is A: <span>along one of the division lines. </span>
4 0
3 years ago
Other questions:
  • The time between requests to a web server is exponentially distributed with mean 0.5 seconds. NOTE: This is a multi-part questio
    8·2 answers
  • The analog signals that carry analog or digital data comprise composites built from combinations of simple sine waves.
    12·1 answer
  • When reading data across the network (i.e. from a URL) in Python 3, what string method must be used to convert it to the interna
    9·1 answer
  • Which element of presentation software can you use to add callouts and banners?
    5·2 answers
  • A vertical curve means that any change in the Aggregate Price Level will have what result?
    15·1 answer
  • John Cleaver is the CEO of Tech World, which is a retail store that sells computers, monitors, cameras, televisions and many oth
    6·1 answer
  • The nl2br() function can be used to convert new line entries in a text area into html ________________ tags.
    13·1 answer
  • What is keylogging attack?
    13·2 answers
  • Discuss briefly four types of websites and the criteria you will use to evaluate the content of a website
    8·1 answer
  • Jackie is planning a surprise birthday party for her best friend and is researching a location to have the party. Jackie found a
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!