major corrections in the files - bad CPPLINT and non-compilable codes

This commit is contained in:
Krishna Vedala
2020-05-25 22:56:38 -04:00
parent 1e5b9f842d
commit baea3b07c1
6 changed files with 145 additions and 203 deletions

View File

@@ -1,53 +1,40 @@
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <cmath>
#include <iostream>
float eq(float i)
{
return (pow(i, 3) - (4 * i) - 9); // original equation
float eq(float i) {
return (std::pow(i, 3) - (4 * i) - 9); // original equation
}
void main()
{
float a, b, x, z;
clrscr();
for (int i = 0; i < 100; i++)
{
z = eq(i);
if (z >= 0)
{
b = i;
a = --i;
goto START;
}
}
int main() {
float a, b, x, z;
START:
for (int i = 0; i < 100; i++) {
z = eq(i);
if (z >= 0) {
b = i;
a = --i;
break;
}
}
cout << "\nFirst initial: " << a;
cout << "\nSecond initial: " << b;
for (i = 0; i < 100; i++)
{
x = (a + b) / 2;
z = eq(x);
cout << "\n\nz: " << z << "\t[" << a << " , " << b << " | Bisect: " << x << "]";
std::cout << "\nFirst initial: " << a;
std::cout << "\nSecond initial: " << b;
for (int i = 0; i < 100; i++) {
x = (a + b) / 2;
z = eq(x);
std::cout << "\n\nz: " << z << "\t[" << a << " , " << b
<< " | Bisect: " << x << "]";
if (z < 0)
{
a = x;
}
else
{
b = x;
}
if (z < 0) {
a = x;
} else {
b = x;
}
if (z > 0 && z < 0.0009) // stoping criteria
{
goto END;
}
}
if (z > 0 && z < 0.0009) // stoping criteria
break;
}
END:
cout << "\n\nRoot: " << x;
getch();
std::cout << "\n\nRoot: " << x;
return 0;
}