title: Rounding error in c integration program
body: <p>im making a program that finds the integral of a function for different values of a power n, and constant a. my program seems to be working correctly but im getting a small rounding error in my results and i cant figure out why. i know i have an error as a friend of mine is also making the same program and his results are slightly different to mine, and his a definitely the right ones as doing the integration on a calculator gives values much closer to his. below are my results and his for a=2 and n=1. </p>
  
  <p>His result: 0.189070<br>
  my result: 0.189053</p>
  
  <p>ive tried going through and casting just about everything i can think of but still cant work out where im getting my error from, any help in pointing out where im being an idiot would be greatly appreciated! :p</p>
  
  <p>My Program:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  #define debug 0
  #define N (double)10000
  
  double Integrand(double x, int a, int n);
  double Integral(double *x, double dx, int a, int n);
  
  int main (int argc, char* argv[])
  {
      int j,a,n=0,count=0,size=(int)N;
      double dx=1/N, x[size];
  
      sscanf(argv[1], "%d", &amp;a);
      for(j=0;j&lt;N;j++) {
          x[j]=(double)(j)*dx;
      }
      for(n=1;n&lt;=10;n++) {
          printf("n is %d integral is %lf\n",n,Integral(x,dx,a,n));
      }    
      return(EXIT_SUCCESS);
  }
  
  double Integral(double *x, double dx, int a, int n)
  {
      int i;
      double result=0;
  
      for(i=0;i&lt;N;i++) {
         result +=(double)((Integrand((double)x[i],a,n))*dx);
      }
      return(result);
  }
  
  double Integrand(double x, int a, int n)
  {
     double result;
     result=(double)(((pow(x,(double)n))/(x+(double)a)));
     return(result);
  }
  </code></pre>