Answer to Question #273104 in C++ for Sarang

Question #273104

LOOPING STATEMENTS AND FUNCTIONS


Create a flowchart to guide you in the process

Create a function that will accept the value of i and return the value of 

Possible values of i is any positive value from 2 to 10

is computed based on the value of i; see the following table for the sample Input / Output

i Process n

3 1*2*3 6

5 1*2*3*4*5 120

7 1*2*3*4*5*6*7 5040


Screen/Layout

(Home Screen)

Input i:3

Process: 1*2*3

Output: 6


Try Another [Y/N]: Y



Input i: 5

Process: 1*2*3*4*5

Output: 120


Try Another [Y/N]: Y




1
Expert's answer
2021-11-29T10:31:53-0500
#include <iostream>


using namespace std;


int foo(int k) {
    int ans = 1;
    while (k--) {
        ans *= k;
    }
    return ans;
}


int main()
{
    while (true) {
        int n;
        char q;
        cout << "Input i: ";
        cin >> n;
        cout << "Output: " << foo(n) << '\n';
        cout << "Try Another [Y/N]: ";
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS