Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

SIMPSON'S 3/8 RULE

Posted By: Adalric Fischer     Category: C Programming     Views: 16072

Write a program of SIMPSON'S 3/8 RULE.

Code for SIMPSON'S 3/8 RULE in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float x[10],y[10],sum=0,h,temp;
  int i,n,j,k=0,l=0;
  float fact(int);
  clrscr();
  printf("\nhow many record you will be enter: ");
  scanf("%d",&n);
  for(i=0; i<n; i++)
  {
   printf("\n\nenter the value of x%d: ",i);
   scanf("%f",&x[i]);
   printf("\n\nenter the value of f(x%d): ",i);
   scanf("%f",&y[i]);
  }
  h=x[1]-x[0];
  n=n-1;
  sum = sum + y[0];
  for(i=1;i<n;i++)
  {
    if(k==0 || l==0)
    {
     sum = sum + 3 * y[i];
     if(k==1)
      {
       l=1;
      }
     k=1;
    }
    else
    {
     sum = sum + 2 * y[i];
     k=0;
     l=0;
    }
   }
   sum = sum + y[i];
   sum = sum * (3*h/8);
   printf("\n\n  I = %f  ",sum);
getch();
}

/*
______________________________________

OUT PUT
______________________________________


how many record you will be enter: 10


enter the value of x0: 0.1


enter the value of f(x0): 1.001


enter the value of x1: 0.2


enter the value of f(x1): 1.008


enter the value of x2: 0.3


enter the value of f(x2): 1.027


enter the value of x3: 0.4


enter the value of f(x3): 1.064


enter the value of x4: 0.5


enter the value of f(x4): 1.125


enter the value of x5: 0.6


enter the value of f(x5): 1.216


enter the value of x6: 0.7


enter the value of f(x6): 1.343


enter the value of x7: 0.8


enter the value of f(x7): 1.512


enter the value of x8: 0.9


enter the value of f(x8): 1.729


enter the value of x9: 1.0


enter the value of f(x9): 2


I = 1.149975


*/
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on SIMPSON'S 3/8 RULE Or get search suggestion and latest updates.

Adalric Fischer
Adalric Fischer author of SIMPSON'S 3/8 RULE is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!