-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (35 loc) · 965 Bytes
/
main.cpp
File metadata and controls
40 lines (35 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <cmath> // Include the cmath header for pow and sqrt functions
double function_for_x(double x)
{
return sqrt(pow(x, 2) + pow(x, 3));
}
int main() {
// Your C++ code goes here
double a;
double b;
double n; //numero de trapecio
double sum;
std::cout << "Write your a value" << std::endl;
std::cin >> a;
std::cout << "Write your b value " << std::endl;
std::cin >> b;
std::cout << "Write your n value " << std::endl;
std::cin >> n;
double delta_x = (b-a)/n;
std::cout << "Your delta X is " << delta_x;
// End of your code
for (double i = 0; i <= n; i += delta_x)
{
if (i == 0 || i == n)
{
sum += function_for_x(i) / 2;
}
else
{
sum += function_for_x(i);
}
}
std::cout << sum << std::endl;
std::cout << function_for_x(20) << std::endl;
}