Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the Printpoly, evaluate, and terms functions. The printpoly function prints the whole polynomial. The evaluate function takes the given value for x and solves

Write the Printpoly, evaluate, and terms functions.

The printpoly function prints the whole polynomial.

The evaluate function takes the given value for "x" and solves the polynomial.

The terms function counts the number of terms in the polynomial.

image text in transcribed

Create a directory called lab9 on your machine using mkdir lab9 and complete the program below. You must write the three functions shown in red (printPoly, evaluate, terms). The code below can be downloaded from the course Blackboard site. lab9.c shown #include # include #include typedef struct poly double coeff int degree; struct poly *next; Poly void printPoly (Poly*) double evaluate (Poly double) int terms (Poly *) int main (void) Poly *myPoly = NULL ; printf ("Enter the coefficient and degree of a term to add to the polynomial "); double ci int d scanf ("%If %d", &c , &d); while ( ! ( fabs (c-0.0) coeffc; newNode->degreed newNode->next = myPoly; myPoly = newNode; printf ("Enter a coefficient and degree (or 0 0 to stop adding terms)"); scanf ( " % 1 f %d", &c, &d); printf (" ") printf ("The polynomial is : "); printPoly (myPoly) printf (" ") printf ("The polynomial has %d terms ", terms (myPoly) ); printf ("Polynomial evaluation - enter a value for x: "); double x; scanf ("%lf", &x) ; printf("\tThe value of the polynomial at x=%lf is %lf ", x, evaluate (myPoly, x) ); return 0 A sample execution of th is program is shown below Enter the coefficient and degree of a term to add to the polynomial:0.5 0 Enter a coefficient and degree (or 0 0 to stop adding terms)1.5 1 Enter a coefficient and degree (or 0 0 to stop adding terms) 2.5 2 Enter a coefficient and degree (or 0 0 to stop adding terms) 3.5 3 Enter a coefficient and degree (or 0 0 to stop adding terms)0 0 The polynomial is: 3.500000 x*3 2.500000 2+1.500000 x*1 + 0.500000 x*0 The polynomial has 4 terms Polynomial evaluation - enter a value for x : 5 The value of the polynomial at x=5.000000 is 508.000000

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions