Thread: Using trapezoidal method to compute integral

  1. #1
    Registered User
    Join Date
    Feb 2012

    Question Using trapezoidal method to compute integral

    The program will compute the integral of a function f.

    The program runs but i am getting wrong values. I am guessing i made mistake somewhere in the formula.

    Answer should look like the following:

    Number of subintervals: 1000000Left endpoint: 0.0Right endpoint: 100.00, answer: 0.886227

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <conio.h>
    double f(double);
    int main()
        double upperBound;
        double lowerBound;
        double n;
        double h;
        printf(" Enter upper and lower bound values \n");
        scanf(" %lf %lf", &upperBound, &lowerBound);
        printf(" Enter number of N values \n");
        scanf(" %lf", &n);
        //h = ((upperBound - lowerBound)/n);
        //double x=lowerBound;
        for (int i=0; i<n; i++)
        //double x = lowerBound;
        double f(double x);
        //x = x + h;
        printf(" The result is %lf\n", f);
    double f(double x)
       return exp(-x*x);
    Thanks For your help.
    I have also attached the file. I am using Dev c++ IDE.
    Attached Files Attached Files

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    This is not a function call. It's just a function declaration.
    double f(double x);
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trapezoidal Rule for Integration
    By lolcats22 in forum C Programming
    Replies: 2
    Last Post: 11-20-2011, 01:09 AM
  2. The trapezoidal rule question
    By paranoidgnu in forum C Programming
    Replies: 9
    Last Post: 04-24-2011, 09:00 AM
  3. Finding the integral by the summation method
    By browser in forum C Programming
    Replies: 4
    Last Post: 12-01-2009, 01:33 PM
  4. composite trapezoidal rule
    By Sam Robinson in forum C Programming
    Replies: 0
    Last Post: 05-19-2003, 10:01 AM
  5. Arrays and the trapezoidal rule
    By ChemistryStar4 in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2003, 08:16 PM