Question
Why isn't my code working? How do I fix this? It is C. #include #include float horner(float p[], int n, float x) { int r
Why isn't my code working?
How do I fix this?
It is C.
#include
float horner(float p[], int n, float x) { int r = 0, i; for (i = 0; i int main(int argc, char* args[]) { //get polynomial efficients from command line arguments if (argc <= 1) { printf("Need more than one arguments, e.g.: 1 2 3 4 "); return 0; } int n = argc-1; // declare float array data structure for coefficients // read command line arguments convert them to floating numbers atof(args[i+1]); // repetitive polynomial evaluation for user input of x value float x = 0.0; do { //get x value from keyboard do { printf("Please enter x value (Ctrl+C or 999 to quit): "); if (scanf("%f", &x) != 1) { printf("Invalid input "); } else { break; } // flush the input buffer while(getchar() !=' '); } while (1); printf("Please enter x value (Ctrl+C or 999 to quit):"); int num = 0; scanf("%d", &num); int h = 999; while (num != h){ printf("1.0*%f^3 + 2.0*%f^2 + 3.0*%f^1 + 4.0*%f^0 = %d ", x , x, x, x, num); printf("Please enter x value (Ctrl+C or 999 to quit):"); scanf("%d", &num); } // write your code // escape when input 999 // print the polynomial expression // use x^n to denote x raised to the n-th power // use %.1f format for floating number // get polynomial's value by calling horner(p, n, x) } while (1); return 0; }
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