a. Create a new program called Sum.c, and type in the following two functions. b
ID: 3729431 • Letter: A
Question
a. Create a new program called Sum.c, and type in the following two functions.
b. Write a few lines in main() to test these functions. Invoke them a couple of times, with a few different values, and see what you get. By some combination of testing and examination of the code, figure out what these functions do, and give them more meaningful names. Add comments that describe their function abstractly.
c. Add a prinf statement to the beginning of both functions so that they print their arguments each time they are invoked. This is a useful technique for debugging recursive programs, since it demonstrates the flow of execution.
Exercise 5.3 a. Create a new program called Sum.c, and type in the following two functions. int FunctionOne (int m, int n) if (m- n) return n;Explanation / Answer
#include <stdio.h>
int addition(int m,int n)
{
printf("m=%d, n=%d ",m,n);
if(m==n)
return n;
else
return m+addition(m+1,n); // recursive function for addition
}
int multiplication(int m,int n)
{
printf("m=%d, n=%d ",m,n);
if(m==n)
return n;
else
return n*multiplication(m,n-1); // recursive function for multiplication
}
int main() {
printf("functionOne : ");
printf("result=%d ",addition(1,2)); // function call
printf("result=%d",addition(2,3)); // function call
printf(" functionTwo : ");
printf("result=%d ",multiplication(3,4)); // function call
printf("result=%d ",multiplication(2,4)); // function call
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.