181k views
3 votes
In C++. Write the definition of function named skipFact. The function receives an integer argument n and returns the product n * n-3 * n-6 * n-9 etc down to the first number less than or equal to 3.

For example skipFact(16) will return the result of 16 * 13 + 10 * 7 * 4 * 1. If n is less than 1 then the function should always return 1.
Just type the function definion, not a whole program. That means you'll submit something like the code below
int skipFact(int n)
{
Il Whatever code you need.
Suggestions:
make a local variable temp of type int and initialize it to 1
make a while loop with the condition n > 1 inside the while loop, use the statement temp *= n
Also inside the while loop, reduce the value of n by 3.
Return temp after the loop.
Write the definition of function named skipFact. The function receives an integer argument in and returns the product nn-3-6 n-3 etc down to the first number
less than or equal to 3
For example skipFact(16) will return the result of 16 13 10 7 41. If n is less than 1 then the function should always return 1.
Just type the function defickton, not a whole program. That means you'll submit something like the code below
int skipFactțint n)
Whatever code you need.
Suggestions
make a local variable temp of type int and initialize it to 1
make a while loop with the condition n > 1
Inside the while loop, use the statement temp = n
Also inside the while loop, reduce the value of n by 3.
Return temp after the loop

1 Answer

5 votes

Final answer:

The function skipFact() is defined in C++ to compute the product of n and all numbers down to the first number less than or equal to 3 at a distance of 3 apart, with a return value of 1 if n is less than 1.

Step-by-step explanation:

Function Definition for skipFact in C++

To compute the product of an integer n and all integers that are a distance of 3 from n down to the first number less than or equal to 3, the function skipFact() can be defined as follows:

int skipFact(int n) {
int temp = 1;
while (n > 1) {
temp *= n;
n -= 3;
}
return temp;
}

The function initializes a local variable temp to 1. As long as n is greater than 1, it multiplies temp by n and then decreases the value of n by 3. When n drops below 1, it returns the calculated product stored in temp.

User Ariya Hidayat
by
7.0k points