Advertisement
Guest User

negar

a guest
Mar 31st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. float my_func(float x,float eps)
  7. { float r=0.0 , a=2*x ;
  8. r=a ;
  9. for( int i=0 ; abs(a)>eps ; ++i)
  10. { a=a*2*x/(i+1) ;
  11. r*=a ;
  12. }
  13. return r;
  14. }
  15.  
  16. void print(float const* const pb,float const* const pe,float eps,float(*pf)(float,float))
  17. {
  18. for (float const*p=pb ; p!=pe ; ++p)
  19. {
  20. std::cout << *p << '\t' ;
  21.  
  22. }
  23. std::cout << '\n' ;
  24. for (float const* p=pb ; p!=pe ; ++p) {
  25. std::cout << pf(*p , eps) << '\t' ;
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. float x[]={1.7,0 ,3.0,4,5};
  32. print(x, x+sizeof(x)/sizeof(x[0]),0.0001,&my_func);
  33. return 1;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement