answersLogoWhite

0


Best Answer

yes. /* trapezoid.c */ #include #include float f(float); float a; float b; float x; float h; float sum; int n; int i; int main() { printf("Enter value for a: "); scanf("%f", &a); printf("Enter value for b: "); scanf("%f", &b); printf("Enter number of rectangles: "); scanf("%d", &n); h = (b - a) / n; sum = (0.5 * h) * (f(a) + f(b)); printf("%f\n", sum); for (i = 1; i < n; i++) { sum = sum + h * f(a + (i * h)); printf("%f\n", sum); } printf("The value of the integral is: %f\n", sum); } float f(float x) { float value; /* define function here */ value = x*x + 3; return value; }

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

// Source: Deepanshu Bhatti Solutions

#include<iostream>

#include<cmath>

using namespace std;

float f (float x)

{

return pow (x,3) + pow (x,2) - (4*x) - 5;

}

int main()

{

float a, b, d, i, n;

float I=0, J=0, A, K=0, E=0;

cout << " Given: f(x) = x^3 + 2x^2 - 4x - 5" << endl;

cout << "Enter lower limit: ";

cin >> a;

cout << "Enter upper Limit: ";

cin >> b;

cout << "Enter the number of intervals: ";

cin >> n;

d = (b - a) / n;

for (i=0; i<=n; ++i)

I = I + f (a + (i * d));

for (i=1; i<n; ++i)

J = J + f (a + (i * d));

A = (d / 2) * (I + J);

cout << "Definite integral: " << A << endl;

for (i=0; i<=n; ++i)

K = K + a + (i * d);

E = -((b - a) * d * d * ((6 * (K / n) + 4) / 12));

cout << "Total error: " << E << endl;

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include

#include


using namespace std;


float f (float x)

{

return pow (x,3) + pow (x,2) - (4*x) - 5;

}


int main()

{

float a, b, d, i, n;

float I=0, J=0, A, K=0, E=0;

cout << " Given: f(x) = x^3 + 2x^2 - 4x - 5" << endl;

cout << "Enter lower limit: ";

cin >> a;

cout << "Enter upper Limit: ";

cin >> b;

cout << "Enter the number of intervals: ";

cin >> n;

d = (b - a) / n;


for (i=0; i<=n; ++i)

I = I + f (a + (i * d));


for (i=1; i

J = J + f (a + (i * d));

A = (d / 2) * (I + J);


cout << "Definite integral: " << A << endl;


for (i=0; i<=n; ++i)

K = K + a + (i * d);


E = -((b - a) * d * d * ((6 * (K / n) + 4) / 12));

cout << "Total error: " << E << endl;

}


// Source: Deepanshu Bhatti Solutions

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Would you write a program for trapezoidal rule in c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write Client and server program in C language using UDP?

Write and run a client and a server program in C-language using UDP


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Write an assembly language program to print a to z on screen?

write a program to print A to Z on screen in c?


Can you write program by c language in dos?

Yes.


What is nature language?

A program that understand what a human would write and be able to transform that into instructions that a computer could understand.


Example of Password program code in assembly language?

How to write the program un Assembly language to set a password for personal computers?


What is natural language interpreter?

A program that understand what a human would write and be able to transform that into instructions that a computer could understand.


What are the advantages and disadvantages of machine language?

AdvantageThe only advantage is that program of machine language run very fast because no translation program is required for the CPU.DisadvantagesIt is very difficult to program in machine language. The programmer has to know details of hardware to write program.The programmer has to remember a lot of codes to write a program which results in program errors.It is difficult to debug the program.


Assembly language program for string concatenation using 8086 microprocessor?

write program to concatenating two sting in 8086 assembly language


Write down a program for hotel management in c language?

ponka


How can program for c language?

first think of the logic and then write the statements


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.