myfunc.cpp 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include "vector.h"
  4. #include "myfunc.h"
  5. //double sqr( double a ) {
  6. //
  7. // return( a * a );
  8. //}
  9. /******************************
  10. double power( double a, int n ) {
  11. double ans = 1.0;
  12. for( int i = 0; i < n; i++ )
  13. ans *= a;
  14. return ans;
  15. }
  16. double power( int a, int n ) {
  17. double ans = 1.0;
  18. double fa = (double) a;
  19. if( n == 0 )
  20. return 1.0;
  21. else if( n > 0 )
  22. for( int i = 0; i < n; i++ )
  23. ans *= fa;
  24. else
  25. for( int i = 0; i < -n; i++ )
  26. ans *= 1.0 / fa;
  27. return ans;
  28. }
  29. double power( double a, double n ) {
  30. if( a == 0.0 ) {
  31. if( n == 0.0 )
  32. return 1.0;
  33. else
  34. return 0.0;
  35. }
  36. return exp( n * log(a) );
  37. }
  38. double integ( Vector& w ) {
  39. double x, sum=0.0;
  40. int N = w.dim();
  41. for( int i = 0; i < N; i++ )
  42. sum += w[i];
  43. sum = (sum - (w[0] + w[N-1]) / 2.0);
  44. return sum;
  45. }
  46. ******************************/