Question: 1.Given the following function, how would you insert it into the main function (int main()) using c++ language. The function should be a case within
1.Given the following function, how would you insert it into the main function (int main()) using c++ language. The function should be a case within a switch statement.
float computeRoot(float root, int index)
{
float tp, mid;
float low = 0;
float high = root;
do
{
mid = (low + high) / 2;
if (Power(mid, index) > root)
{
high = mid;
}
else
{
low = mid;
}
mid = (low + high) / 2;
tp = (computePower(mid, index) - root);
if (tp < 0)
{//grab absolute value
tp = tp * (-1.0);
}
} while (tp > .000005);//accuracy of our root
return mid;
}
2. Given two function functions that find the greatest and lowest common denominator, what would you include in the main function that would make sure the function only executed if the user inputted postive integers. The functions are given below.
int computeGCD(int a, int b)
{
while (a != b)
{
if (a > b)
{
a = a - b;
}
else
{
b = b - a;
}
}
return a;
}
int computeLCM(int a, int b)
{
int tmp_lcm;
tmp_lcm = ((a * b) / GCD(a, b));
return tmp_lcm;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
