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;
}

View File

@@ -1,53 +0,0 @@
#include <iostream.h>
#include <conio.h>
#include <math.h>
float eq(float i)
{
return (pow(i, 3) - (4 * i) - 9); // original equation
}
float eq_der(float i)
{
return ((3 * pow(i, 2)) - 4); // derivative of 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;
c = (a + b) / 2;
for (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
{
goto END;
}
}
END:
cout << "\n\nRoot: " << z;
getch();
}

View File

@@ -1,49 +1,37 @@
#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 (pow(i, 3) - (4 * i) - 9); // original 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;
}
}
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;
}
}
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);
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 = b;
b = c;
c = ((a * n) - (b * m)) / (n - m);
a = b;
b = c;
z = eq(c);
if (z > 0 && z < 0.09) // stoping criteria
break;
}
z = eq(c);
if (z > 0 && z < 0.09) // stoping criteria
{
goto END;
}
}
END:
cout << "\n\nRoot: " << c;
getch();
std::cout << "\n\nRoot: " << c;
return 0;
}

View File

@@ -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;
}

View File

@@ -1,37 +1,28 @@
#include <conio.h>
#include <iostream.h>
#include <math.h>
float eq(float y)
{
return ((3 * y) - (cos(y)) - 2);
#include <cmath>
#include <iostream>
float eq(float y) { return ((3 * y) - (cos(y)) - 2); }
float eqd(float y) { return ((0.5) * ((cos(y)) + 2)); }
int main() {
float y, x1, x2, x3, sum, s, a, f1, f2, gd;
int i, n;
for (i = 0; i < 10; i++) {
sum = eq(y);
std::cout << "value of equation at " << i << " " << sum << "\n";
y++;
}
std::cout << "enter the x1->";
std::cin >> x1;
std::cout << "enter the no iteration to perform->\n";
std::cin >> n;
for (i = 0; i <= n; i++) {
x2 = eqd(x1);
std::cout << "\nenter the x2->" << x2;
x1 = x2;
}
return 0;
}
float eqd(float y)
{
return ((0.5) * ((cos(y)) + 2));
}
void main()
{
float y, x1, x2, x3, sum, s, a, f1, f2, gd;
int i, n;
clrscr();
for (i = 0; i < 10; i++)
{
sum = eq(y);
cout << "value of equation at " << i << " " << sum << "\n";
y++;
}
cout << "enter the x1->";
cin >> x1;
cout << "enter the no iteration to perform->\n";
cin >> n;
for (i = 0; i <= n; i++)
{
x2 = eqd(x1);
cout << "\nenter the x2->" << x2;
x1 = x2;
}
getch();
}

View File

@@ -1,67 +1,56 @@
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// Declaring variables for maintaing prime numbers and to check whether a number is prime or not
// Declaring variables for maintaing prime numbers and to check whether a number
// is prime or not
bool isprime[1000006];
vector<int> prime_numbers;
vector<pair<int, int>> factors;
// Calculating prime number upto a given range
void SieveOfEratosthenes(int N)
{
void SieveOfEratosthenes(int N) {
// initializes the array isprime
memset(isprime, true, sizeof isprime);
for (int i = 2; i <= N; i++)
{
if (isprime[i])
{
for (int j = 2 * i; j <= N; j += i)
isprime[j] = false;
for (int i = 2; i <= N; i++) {
if (isprime[i]) {
for (int j = 2 * i; j <= N; j += i) isprime[j] = false;
}
}
for (int i = 2; i <= N; i++)
{
if (isprime[i])
prime_numbers.push_back(i);
for (int i = 2; i <= N; i++) {
if (isprime[i]) prime_numbers.push_back(i);
}
}
// Prime factorization of a number
void prime_factorization(int num)
{
void prime_factorization(int num) {
int number = num;
for (int i = 0; prime_numbers[i] <= num; i++)
{
for (int i = 0; prime_numbers[i] <= num; i++) {
int count = 0;
// termination condition
if (number == 1)
{
if (number == 1) {
break;
}
while (number % prime_numbers[i] == 0)
{
while (number % prime_numbers[i] == 0) {
count++;
number = number / prime_numbers[i];
}
if (count)
factors.push_back(make_pair(prime_numbers[i], count));
if (count) factors.push_back(make_pair(prime_numbers[i], count));
}
}
/*
I added a simple UI.
*/
int main()
{
int main() {
int num;
cout << "\t\tComputes the prime factorization\n\n";
cout << "Type in a number: ";
@@ -72,8 +61,7 @@ int main()
prime_factorization(num);
// Prime factors with their powers in the given number in new line
for (auto it : factors)
{
for (auto it : factors) {
cout << it.first << " " << it.second << endl;
}