Question
Sample output: $ ./polynomial Please enter a positive integer: -1 Please enter a positive integer: 0 Please enter a positive integer: 1 f(1) = 6
Sample output:
$ ./polynomial Please enter a positive integer: -1
Please enter a positive integer: 0
Please enter a positive integer: 1
f(1) = 6 Please enter a positive integer: 2
f(2) = 17 Please enter a positive integer: 3
f(3) = 34 Please enter a positive integer: 4
f(4) = 57 Please enter a positive integer: 5
f(5) = 86
#include
#include
const int BUFFER_LEN = 256;
int obtainPositiveInt ()
{
char buffer[BUFFER_LEN];
int toReturn;
// YOUR CODE HERE
return(toReturn);
}
void computePolynomialOf (int n, int* resultPtr)
{
// YOUR CODE HERE
}
int main () {
while (1)
{
int result;
int n = obtainPositiveInt();
// YOUR CODE HERE TO CALL computePolynomialOf()
printf("f(%d) = %d ",n,result);
}
return(EXIT_SUCCESS);
}
2. C and Pointers (10 points): Finish the program below that in a loop: 1. Uses obtainPositiveInt() to ask for, and obtain, a positive integer. (If it 2. Uses computePolynomial) to compute the function 3n2 2n 1. n comes 3. Prints out both n and result keeps asking if the user does not give one). This number becomes the number n in main(). into the function as an integer, but the address of result is comes into computePolynomial() for it to change its value directly. Sample output: $ ./polynomial Please enter a positive integer: -1 Please enter a positive integer: 0 Please enter a positive integer: 1 Please enter a positive integer: 2 f (2)17 Please enter a positive integer: 3 f (3)34 Please enter a positive integer: 4 f (4)57 Please enter a positive integer: 5 f (5)86 #include #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started