F Trapezoidal Rule Program In C | CodeTheta

Trapezoidal Rule Program In C

May 08, 2014

Here is a very popular Trapezoidal Rule which is written in c programming. In this program we use all float number to get result in float value. In this program when we will execute this program we will see that it will ask for the limit of value after that it will ask for subintervals after that you will get the result by Trapezoidal Rule. The Mechanism of this program is here:
for(k=a;k<=b;k+=h)
   {
     if((k==a)||(k==b))
        i+=f(k);
     else
        i+=2*f(k);
   }
   i=(h/2)*(i);
 
 
/******************************************     
 Trapezoidal Rule
 ******************************************/


#include<stdio.h>
#include<conio.h>
#define MAX 20
#define f(x) (x)
void main()

{
   float a,b,h,i,k;
   float x[MAX],y[MAX];
   int n;
   printf("http://native-code.blogspot.com/");
   printf("\nEnter the limits:");
   scanf("%f %f",&a,&b);
   printf("\nEnter the number of subintervals:");
   scanf("%d",&n);
   h=(b-a)/n;
   for(k=a;k<=b;k+=h)
   {
     if((k==a)||(k==b))
        i+=f(k);
     else
        i+=2*f(k);
   }
   i=(h/2)*(i);
   printf("\n\n\nResult:%f",i);
   getch();
} 


/* http://native-code.blogspot.com/ */
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us

Post a Comment