c, Computer Engineering

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

 

#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:43:56 AM | Location : United States







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

Write discussion on c
Your posts are moderated
Related Questions
What is the importance of XML into EDI and electronic commerce? XML has been explained as lightweight SGML: XML demonstrates great promise for its inherent capability to per

quick sort working

Memory - management mode System memory-management mode (SMM) is on the same level as protected mode, real mode and virtual mode though it is provided to function as a manager

What is Difference between write back and write through cache? A caching method wherein modifications to data into the cache aren't copied to the cache source till absolutely n

Q. Explain about Decimal Numbers? Decimal number system has 10 digits signified by 0,1,2,3,4,5,6,7,8 and 9. Any decimal number can be signified as a string of these digits an

Q. Show Network Topology in digital system? This deals with the geometrical arrangement of nodes (endpoints consisting of physical devices such as terminals, printers, PCs, and

Question 1 What are the drivers behind the convergence between voice and data networks? Explain them briefly Question 2 Explain the need and functioning of Private ST Netw

IT Management 1. Describe how the IT infrastructure is designed. 2. Explain briefly the audit planning phase in IT Audit 3. Explain localized and distributed load balanci

If you need to line up the cells next to each other you can resize and move layout cells as you need. You can change size of a layout cell by using one of its resize handles. Yo

Disadvantages of Address translation: Disadvantages are following: A program that is too large to be held in a part needs some special design, that called overlay