#include <stdio.h> #include <time.h> #include <math.h>clock_t start ,stop;double Duration, #define MAXN 10 #define &NBSP;MAXK&NBSP;1E7DOUBLE&NBSP;F1 (int n ,double a[],double x);d ouble f2 (int n ,double a[],double x); Int main () {int i; Double a[maxn];for ( i = 0; i<maxn ; i++) a[i] = (double) I;start = clock (); for ( i = 0; i<maxk; i++) {F1 (maxn-1 , a,1.1);} Stop = clock ();d uration = ((double) (Stop - start))/clk_tck/maxk;printf ("Ticks1 = %f\n ", (Double) (Stop-start));p rintf (" duration1 = %6.2e\n ", duration); start = clock (); for ( i = 0; i<maxk ; i++) {F2 (maxn-1 , a,1.1);} Stop = clock ();d uration = ((double) (Stop - start))/clk_tck/maxk;printf ("Ticks2 = %f\n ", (Double) (Stop-start));p rintf ("duration2 = %6.2e\n", duration);} DOUBLE&NBSP;F1 (int n , double a[] , double x) {int i;double p =a[0];for ( i=1 ; i<= n; i++) p += (A[i]*pow (x,i)); return p;} DOUBLE&NBSP;F2 (int n , double a[] , double x) {int i;double p = a[n];for ( i = n ; i > 0 ; i--) p = a[i-1 ] + x*p;return p;}
Data structure learning notes solving polynomial