areaundercurve.c, C/C++ Programming

Assignment Help:

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

 

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


Related Discussions:- areaundercurve.c

What are user defined data types, Q: What are User Defined data types? ...

Q: What are User Defined data types? C supports an extraordinary feature known as "type definition" that permits users to define an identifier that would represent an existing

Scrape a site and save as csv, Scrape a site and save as csv Project Des...

Scrape a site and save as csv Project Description: I want a programmer to create scraping software. I'll want every page scraped of name, job title, company, and url. There a

Palindrome, string S convert it to a palindrome by doing chara, C/C++ Progr...

string S convert it to a palindrome by doing chara, C/C++ Programming

Help, Deliverables: you are required to upload your c code in the assignmen...

Deliverables: you are required to upload your c code in the assignment dropbox set in Moodle. You are supposed to work with Linux gcc compiler and pico editor for compiling via the

A string S convert it to a palindrome by doing chara, A palindrome is a str...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Explain input output function, Input Output Most languages have "statem...

Input Output Most languages have "statements" to perform I/O . Though in C and C++ we use "functions" to perform I/O. C++ also has its own I/O mechanism - the cin and cout obje

Does improper inheritance have potential to wreck a project, Does improper ...

Does improper inheritance have a potential to wreck a project? Many projects meet a dead end due to bad inheritance. Hence it certainly has potential to wreck a project. Sma

Write a program to illustrate array with strings, Write a Program to illust...

Write a Program to illustrate Array with Strings? main() { static char name[]="devdas"; int i; i=0; while(name[i]!='\0') { printf("%c",name[i]); i=i+1; } } In the

Computer Science Engineering C++ Homework, Temperature Conversions. Problem...

Temperature Conversions. Problems 28 through30generate temperature-conversion tables. Use the following equations that give relationships between temperatures in degrees Fahrenheit

Explain in brief about the one-definition rule, Explain one-definition rule...

Explain one-definition rule (ODR). According to one-definition rule, C++ constructs should be identically defined in each compilation unit they are used in. As per ODR, two

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd