mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-04 02:59:43 +08:00
major corrections in the files - bad CPPLINT and non-compilable codes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
float eq(float i) {
|
||||
return (std::pow(i, 3) - (4 * i) - 9); // original equation
|
||||
}
|
||||
float eq_der(float i) {
|
||||
return ((3 * std::pow(i, 2)) - 4); // derivative of equation
|
||||
}
|
||||
|
||||
int main() {
|
||||
float a, b, z, c, m, n;
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
z = eq(i);
|
||||
if (z >= 0) {
|
||||
b = i;
|
||||
a = --i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\nFirst initial: " << a;
|
||||
std::cout << "\nSecond initial: " << b;
|
||||
c = (a + b) / 2;
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
float h;
|
||||
m = eq(c);
|
||||
n = eq_der(c);
|
||||
|
||||
z = c - (m / n);
|
||||
c = z;
|
||||
|
||||
if (m > 0 && m < 0.009) // stoping criteria
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "\n\nRoot: " << z << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user