areaundercurve.c, C/C++ Programming

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw



float    start_point,            /* GLOBAL VARIABLES */

int    numtraps;
main( )
   void    input(void);
   float    find_area(float a,float b,int n); /* prototype */

   print(“AREA UNDER A CURVE”);
   input( );
   total_area = find_area(start_point, end_point, numtraps);
   printf(“TOTAL AREA = %f”, total_area);
void input(void)
   printf(“\n Enter lower limit:”);
   scanf(“%f”, &start_point);
   printf(“Enter upper limit:”);
   scanf(“%f”, &end_point);
   printf(“Enter number of trapezoids:”);
   scanf(“%d”, &numtraps);
float find_area(float a, float b, int n)
      floatbase, lower, h1, h2;    /* LOCAL VARIABLES */
float function_x(float x);    /* prototype */
float trap_area(float h1,float h2,floatbase);/*prototype*/
base = (b-1)/n;
         lower = a;
       for(lower =a; lower <= b-base; lower = lower + base)
    h1  =  function_x(lower);
             h1  =  function_x(lower + base);
             total_area += trap_area(h1, h2, base);
    float trap_area(float height_1,float height_2,floatbase)
       float area;    /* LOCAL VARIABLE */

       area = 0.5 * (height_1 + height_2) * base;
    float function_x(float x)
         /* F(X) = X * X + 1 */
return(x*x + 1);

    Enter lower limit: 0
    Enter upper limit:  3
    Enter number of trapezoids: 30
    TOTAL AREA   =  12.005000

    Enter lower limit: 0
    Enter upper limit: 3
    Enter number of trapezoids: 100
    TOTAL AREA = 12.000438

Posted Date: 9/3/2012 2:04:21 AM | Location : United States

Related Discussions:- areaundercurve.c, Assignment Help, Ask Question on areaundercurve.c, Get Answer, Expert's Help, areaundercurve.c Discussions

Write discussion on areaundercurve.c
Your posts are moderated
Related Questions

Returning References from Functions Just as in passing the parameters by reference, returning a reference also doesn't return back a copy of the variable , instead an alias is

draw the flow chart to print the fibonacci series upto n th terms

Should one design a classes from the outside (interfaces first) or inside (data first)? A: From the outside. A superior interface provides a simplified view which is express

#question.Write a c++ program to accept and print a 1_d array

how to use nested loop of for in array

A: The procedure of encoding the parameter types along with the function/method name into a unique name is called as name mangling. The inverse procedure is called demangling. F

Rahul is a newbie to the programming and while learning the programming language he came to know the following rules: · Each program must start with ''{'' and end with '

print this pattern 1 01 101 0101