c program, Computer Engineering

program for finding the area under the curve

 

#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) { float base , lower, h1, h2; /* LOCAL VARIABLES */
float function_x(float x); /* prototype */
float trap_area(float h1,float h2,float base );/*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,float base ) { 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/2/2012 1:22:00 AM | Location : United States







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

Write discussion on c program
Your posts are moderated
Related Questions
Define a Gate Fix ASIC-based design in short. Gate Fix ASIC-based design: A Gate Fix implies that a select number of gates and their interconnections may be subtracted or ad

It is not essential to maintain the Parent-Child relationship among the tables in Logical Database Structure. False. One has to handle the Parent-Child relationship.

Benefits and benefits of LINQ are: 1. Makes it simpler to transform data into objects. 2. A common syntax for all data. 3. Strongly typed code. 4. Provider integration.

What are the different modes in that 8255 Programmable Peripheral Interface (PPI) can operate?  24 I/O lines in 3-8-bit port groups - A, B, C A, B can be 8-bit input

The various memory allocation functions are described below: (i) malloc( ) : It is a memory allocation function that assigns requested size of bytes and returns a pointer to t

Electric typewriter : Electric typewriters are similar to standard typewriters but with an electronic motor taking the place of human energy. It is much faster than the standard m

Explain Readers-writers problem. Readers-writers problem: Assume that a data object (as a file or record) is to be shared between several concurrent processes. The readers ar

Magento is a feature-rich eCommerce platform built on open-source technology that gives online merchants with unprecedented flexibility and control over the look, content and funct

he trick to calling script-fu-scripts from any more script is to just reference the main define for the script and not to try to use the pdb call. All the scripts in script-fu shar

Why a computer expect to receive responses when it broadcast an ARP request? Response will be acquired only from the machine for that request is being sent not for the other ma