In the following program the compiler rejects the return sta
In the following program the compiler rejects the \"return\" statement in the function \"product\". Fix the declaration of z to correct this error. #include float product(float x, float y) {int z; z = x * y; return z;} int main() {float r = 4.5; float q = 7.6; float s = product(q, r); printf (\"The product of %f and %f\ \", q, r, s); return 0;} Here is the mathematical definition of the factorial function: Factorial(n) = {1 n = 0 n middot Factorial (n - 1) otherwise And here is an incorrect attempt to represent that definition in C: int Factorial(int n) {if (n == 0) return 1; else return n * (n - 1); Correct the function so it implements the Factorial algorithm correctly.
Solution
9.
float product(float x,float y)
{
float z; // z should be declared float type
z = x*y;
return z;
}
10.
#include <stdio.h>
int Factorial(int n)
{
if(n==0) return 1;
else return n * Factorial(n-1); //recursive call to Factorial() function
}
int main(void)
{
int n =5;
printf(\" The Factorial of % d = %d\",n,Factorial(n));
return 0;
}
Output:
Success time: 0 memory: 2168 signal:0
