Data structure learning note solving polynomial 2

Source: Internet
Author: User

#include <stdio.h> #include <time.h> #include <math.h> #define  maxrepeat 1e7#define  maxn 101 typedef double (*func) (int, double );void timecost  (func  myfunc , int n , double x);d ouble func1 (int n , double  x);d Ouble func2 (int n , double x); Int main (int argc , const  char *argv[]) {int n =maxn;double x = 1.1;printf ("fun1 Result:%lf\n",  Func1 (n,x)); Timecost (func1 , n, x);p rintf ("Func2 Result:%lf\n", Func2 (n,x)); Timecost (func2, n &NBSP;,X); return 0;} void timecost  (func myfunc , int n , double x) {Clock_t start  , stop;double duration;start = clock (); Int i;for ( i = 0; i  < maxrepeat ; i++) {myFunc (n,x);} stop = clock  ();d uration =  ((Double) (Stop-start))/clocks_per_sec;printf ("spents%f seconds \ n", duration);} DOUBLE&NBSP;FUNC1 (int n, double x) {double p =1;int i;for ( i =1 ;i <n;i++) {P += pow (x,i)//;} Return p;} DOUBLE&NBSP;FUNC2 (int n ,double x) {double p =1.0/(n-1); Int i =0;for (i  = n-1 ;i> 0 ; i--) {if (i ==1) {p = 1+x*p;} else{p =1.0/(i-1)  + x*p;}} Return p;}


Data structure learning note solving polynomial 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.