Trapezoidal Rule

Source Code:

Write a program in C to find the value of using the Trapezoidal Rule with 𝒏 = 4

#include <stdio.h>
#include <conio.h>
double f(double x){ return x*x + 1; }
int main(){
    clrscr();
    int n=4; double a=0, b=1, h, sum=0;
    h=(b-a)/n;
    for(int i=1;i<n;i++)
    sum += f(a+i*h);
    double I = h/2*(f(a)+f(b)+2*sum);
    printf("\n\n\tIntegral : %.4f\n", I);
    getch();
    return 0;
}

Output