Area under Curve, C/C++ Programming

#queWrite 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 two points can be found by doing a definite integral between the two pointsstion..

Solution :

#include
float    start_point,            /* GLOBAL VARIABLES */

    end_point,
    total_area;
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);
    }
return(total_area);
    float trap_area(float height_1,float height_2,floatbase)
        {
       float area;    /* LOCAL VARIABLE */

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

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

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

Posted Date: 9/3/2012 2:58:29 AM | Location : United States







Related Discussions:- Area under Curve, Assignment Help, Ask Question on Area under Curve, Get Answer, Expert's Help, Area under Curve Discussions

Write discussion on Area under Curve
Your posts are moderated
Related Questions
Question 1: (a) Explain clearly the following concepts using suitable examples of your own:- (i) concrete class v/s abstract class (ii) constructor v/s over

What is abstraction? - Simplified view of an object in user's language is termed as abstraction. - It's the simplest, well-defined interface to an object in OO and C++ which

Write a ''C'' program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number

what is local and global variable?give me some example to understand better

Can copy constructor admit an object of the same class as parameter, rather than reference of the object?

wap to print padovan string in c

What does throw; (with no exception object after the throw keyword) mean? Where would I employ it? A: You should see code that looks something like this: class MyException

Question 1 Consider you have to find out average marks of 100 students in a class. Write simple program(s) using different iteration statements to accomplish it Question 2 Expla

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Expected output of the program: 1. Consider the following programs. For each, indicate whether the program is correct. If yes, what is the expected output? If not, what is the