[ create a new paste ] login | about

Link: http://codepad.org/4yqhUejx    [ raw code | output | fork ]

C, pasted on Dec 6:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
  {
  return (sqrt(exp(x)-1));
  }

float S(int n)
  {
  int i;
  float S1, S2, h, a=0, b=log(2);
  h =(b - a) / (2*n);
  for (i = 1; i <= 2*n-1; i++)
  {
        if (i % 2 == 0)
            S1 += 2 * f(a + i * h);
        else S1+= 4 * f(a + i * h);
  }
    S2=((f(a)+f(b)+S1))*h/3;
  return S2;
  }

main()
{
float  N = 12, q=2*N, w=4*N;
float c, d, e, k, j;
clrscr();
q=2*N;
w=4*N;
e=0.001;
c = S(q);
   do
   {
     d = c;
     q*=2;
     c=S(q);
    }
while(fabs(d-c))>e);
   k=S(q);
printf("\nIntegral:  %f", k);
getch();
return 0;
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'main':
Line 39: error: expected ';' before '>' token


Create a new paste based on this one


Comments: