In the following program the compiler rejects the \"return\" statement in the fu
ID: 3931465 • Letter: I
Question
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.Explanation / Answer
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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.