Wednesday 20 May 2015

How to write a “C” Program for finding the Numerical Integration by Simpson's 1/3rd Rule and the Absolute and Relative Error form the exact value.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
{
  float x[15],y[15],sum=0,h,temp,E,RE,E1;
  int i,n,j,k=0;
  float fact(int);
  clrscr();
  printf("\n how many record you will be enter: ");
  scanf("%d",&n);
  for(i=0;i<=n;i++)
  {
  printf("\n ENTER THE VALUE OF x%d: ",i);
  scanf("%f",&x[i]);
  printf("\n ENTER THE VALUE OF f(x%d): ",i);
  scanf("%f",&y[i]);
  }
  h=x[1]-x[0];
  n=n-1;
  for(i=0;i<=n;i++)
  {
  if(k==0)
  {
  sum=sum+4*y[i];
  k=1;
  }
  else
  sum=sum+2*y[i];
  k=0;
  }
  sum=sum+y[i];
  sum=sum*h/3;
  printf("\n\n I=%f ",sum);
  E=sum-1;
  printf("\n\n ABSOLUTE ERROR: E=%f ",E);
  RE=E*100;
  printf("\n\n RELATIVE ERROR: RE=%f% ",RE);
  getch();
  }
  }

No comments:

Post a Comment