Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sample output: $ ./polynomial Please enter a positive integer: -1 Please enter a positive integer: 0 Please enter a positive integer: 1 f(1) = 6

image text in transcribed

image text in transcribed

image text in transcribed

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 BUFFER LEN obtainPositiveInt const int -256; int 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 int result; obtainPositiveInt(); // YOUR CODE HERE TO CALL computePolynomialof () printf("f(sd) %d ",n, result); - return (EXITSUCCESS)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

ISBN: 1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

True or False sin() + cos() = cos sin

Answered: 1 week ago

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago