Wednesday 14 December 2011

c program of simpson's 3/8 rule.



C  Propgram to implement simpson's 3/8rd rule.

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<process.h>
#include<string.h>
float fun(float);
void main()
{
 float result=1;
 float a,b;
 float h,sum;
 int i,j;
 int n;
 clrscr();
 printf("\n\n Enter the range-");
 printf("\n\n Lower Limit a-");
 scanf("%f",&a);
 printf("\n\n Upper Limit b-");
 scanf("%f",&b);
 printf("\n\n Enter number of subintervals-");
 scanf("%d",&n);
 h=(b-a)/n;
 sum=0;
 sum=fun(a)+fun(b);
 for(i=1;i<n;i++)
 {
   if(i%3==0)
   {
     sum+=2*fun(a+i*h);
     }
     else
     {
       sum+=3*fun(a+(i)*h);
       }
       }
       result=sum*3*h/8;
       printf("\n\n\n Value of the intergal is %6.4f\t",result);
       printf("Press enter to Exit");
       getch();
       }
       float fun(float x)
       {
             float temp;
             temp=1/(1+(x*x));
             return temp;
             }

1 comment:

  1. Informative article, just what I was looking for. Well, Do you have any video of that? I’d love to find out some additional information.

    BEST Medical Websites for Medical Clinics.

    ReplyDelete