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
Explain the Loop Statements in Computer Programming? 1. C gives you a choice of three kinds of loop, while, do while and for. 2. The while loop remain repeating an action until

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

1. De ne a function chomp :: String -> String that selects a run of repeated characters from the start of a string with the run being as long as possible. For example ch

Question 1) What are the commonly used input/output functions in C? Question 2) What is the difference between function declaration and function definition? Write a recursive

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

how can i make a program with !(not) operator

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

C Program for FUNCTION OF FIND THE FACTORIAL float factorial(float); void main() {           float i=0,c=0;           clrscr();           printf("ENTER THE DIGI

Pointer Arithmetic We can manipulate the pointers too. We can perform operations such as addition, subtraction, increment and decrement etc.,. As the pointer variables have add

How to use HTTP Headers inside PHP? Write the statement through which it can be added? HTTP headers can be used in PHP by redirection that is written as: Headers can be