[ create a new paste ] login | about

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

C, pasted on May 22:
/* Simpsons 1/3 rule */
#include<math.h>
#include<stdio.h>
#include<conio.h>
float f(float x)
{
      float f;
      f=sin(x);
      return(f);
      }
     // #define f(x) (1/(1+x*x))
      main()
      {
            float a,b,h,simp;
            int n,k;
            printf("Value of a,b,n    ");     
            scanf("%f%f%d",&a,&b,&n);
            h=(b-a)/n;
            
            simp=f(a)+f(b); 
            for(k=1;k<n;k=k+2)
            {
            simp=simp+4*f(a+h*k);
            
       }
       for(k=2;k<n;k=k+2)
            {
            simp=simp+2*f(a+h*k);
            
       }
            simp=simp*h/3;
            printf("\n simp=%f",simp);
            getch();
            }
            
            


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments: