area under the curve, C/C++ Programming

Area under the curve
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 between a & b


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:19:06 AM | Location : United States

Related Discussions:- area under the curve, Assignment Help, Ask Question on area under the curve, Get Answer, Expert's Help, area under the curve Discussions

Write discussion on area under the curve
Your posts are moderated
Related Questions
I have an exercise with 2 problems. One that is partially completed except with read problems with memory overwrite, and the other problem. I have enclosed the instructions documen

Define Array of Structures? An Array of Structures is an assortment of the same data types which are declared as structures. It is useful to store large and different number of

void main() { int *p, *q, i ; p=(int*)100; q=(int*)200; i=q-p; printf("%d",i); } }

Define a structure to store roll no, name and marks of a student. b) Using the structure of Q2. a), above write a ''C'' program to create a file "student.dat". There must be one r

Write a c program to determine interchanged values between two variables?[Hint - if loop] What will be the output of the program? How many times this loop will execute? Wr

Within software languages we have the ability to store information in mail boxes i.e. memory slots which are given names to represent the box. The naming rules are governed by the

Define Advantages of Multi File Program? The main merits of spreading a program across several files are: • Teams of programmers able to work on programs. Every programmer w

a) Define an Asset base class that provides the following method: class Asset { public:      virtual double getValue()=0; };   This will be the base class for both stock an

v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} Normal 0

Abstract Classes Abstract classes are the classes, which are written just to act as base classes. Consider the following classes.                 class base