diff --git a/computer_oriented_statistical_methods/false-position.CPP b/computer_oriented_statistical_methods/false-position.CPP deleted file mode 100644 index 847a74df1..000000000 --- a/computer_oriented_statistical_methods/false-position.CPP +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include - -float eq(float i) -{ - return (pow(i, 3) - (4 * i) - 9); // origial equation -} - -void main() -{ - float a, b, z, c, m, n; - clrscr(); - for (int i = 0; i < 100; i++) - { - z = eq(i); - if (z >= 0) - { - b = i; - a = --i; - goto START; - } - } - -START: - - cout << "\nFirst initial: " << a; - cout << "\nSecond initial: " << b; - for (i = 0; i < 100; i++) - { - - float h, d; - m = eq(a); - n = eq(b); - - c = ((a * n) - (b * m)) / (n - m); - a = c; - - z = eq(c); - if (z > 0 && z < 0.09) // stoping criteria - { - goto END; - } - } - -END: - cout << "\n\nRoot: " << c; - getch(); -} diff --git a/computer_oriented_statistical_methods/false-position.cpp b/computer_oriented_statistical_methods/false-position.cpp new file mode 100644 index 000000000..5e15e92cc --- /dev/null +++ b/computer_oriented_statistical_methods/false-position.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +float eq(float i) { + return (pow(i, 3) - (4 * i) - 9); // origial equation +} +int main() { + float a, b, z, c, m, n; + system("clear"); + for (int i = 0; i < 100; i++) { + z = eq(i); + if (z >= 0) { + b = i; + a = --i; + goto START; + } + } + START: + std::cout << "\nFirst initial: " << a; + std::cout << "\nSecond initial: " << b; + for (int i = 0; i < 100; i++) { + float h, d; + m = eq(a); + n = eq(b); + c = ((a * n) - (b * m)) / (n - m); + a = c; + z = eq(c); + if (z > 0 && z < 0.09) { // stoping criteria + goto END; + } + } + END: + std::cout << "\n\nRoot: " << c; + system("pause"); +}