Code for Waddle’s Rule method in C

C code to implement  Waddle’s Rule  method .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float);
 float f(float x)
  {
        float y;
        y=1/(1+x*x);
        return(y);
  }                          
main()
{
      float a,b,h,s1=0,s2=0,s=0;
      int i,n,m;
      printf("Enter the value of upper limit= ");
      scanf("%f",&b);
       printf("Enter the value of lower limit= ");
      scanf("%f",&a);
       printf("Enter the value of n=");
      scanf("%d",&n);
      h=(b-a)/n;
      printf("h= %f",h);
      m=n/6;
      s=0;
      if(n%6==0)
      {
      for(i=1;i<=m;i++)
          {
          s=s+((3*h/10)*(f(a)+f(a+2*h)+5*f(a+h)+6*f(a+3*h)+f(a+4*h)+5*f(a+5*h)+f(a+6*h)));  
          a=a+6*h;  
          }
          printf("Result is : %f",s);
       }
        else
          {
              printf(" Weddle's rule is not applicable");
          }         
              getch();
   }

website_caption1

 You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s