/* ******************************************** A program to illustrate the use of functions Computes the polynomial ax^6+bx^4+cx^2+d=0 Uses square() and quartic() as simple examples of function modules to perform abstracted tasks. Square() is located in a second file. G.C. Rutledge October 2002 ****************************************** */ #include double square(double); /* This is a function PROTOTYPE */ double quartic(double); int main(void) { double a=1.0, b=1.0, c=1.0, d=1.0; double x, f; printf("This program computes x^6+x^4+x^2+1.\n"); printf("Input a value for x: \n"); scanf("%lf",&x); /* Task 1: initailize f(x) */ f = d; /* Task 2: compute x^2 term */ f += c*square(x); /* this is a function INVOCATION */ /* Task 3: compute x^4 term */ f += b*quartic(x); /* Task 4: compute x^6 term */ /* Notice reuse of quartic() and square() functions */ f += a*quartic(x)*square(x); printf("The value of this polynomial at x=%f is %f\n",x,f); return (0); } /* ************************************************ This is the DEFINITION of the quartic() function. It returns the value of z^4. G.C. Rutledge October 2002 ************************************************ */ double quartic(double z) { double z4; /* Note that functions can call other functions */ z4 = square(z)*square(z); return z4; }