Ayuda para pasar de C++ a C
Publicado por Juan Morales (1 intervención) el 23/03/2020 04:32:34
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
// Headers
string toString (double);
int toInt (string);
double toDouble (string);
int main() {
double a, b, c, d, x1, x2, r, r2, m, m2;
cout << "Deme los coeficientes" << endl;
cout << "Introduzca el valor de a:" << endl;
cin >> a;
cout << "Introduzca el valor de b:" << endl;
cin >> b;
cout << "Introduzca el valor de c:" << endl;
cin >> c;
if (a == 0) {
cout << "No es ecuacion de segundo grado" << endl;
} else {
d = b * b - 4 * a * c;
if (d == 0) {
x1 = -b / (2 * a);
x2 = x1;
cout << "La raiz uno es:" << x1 << endl;
cout << "La raiz dos es:" << x2 << endl;
} else {
if (d > 0) {
x1 = (-b + pow(d, 0.5)) / (2 * a);
x2 = (-b - pow(d, 0.5)) / (2 * a);
cout << "La raiz uno es:" << x1 << endl;
cout << "La raiz dos es:" << x2 << endl;
} else {
r = -b / (2 * a);
r2 = pow(-d, 0.5) / (2 * a);
m = -b / (2 * a);
m2 = pow(-d, 0.5) / (2 * a);
cout << "La raiz uno es:" << r;
cout << "+";
cout << "" << r2;
cout << "i" << endl;
cout << "La raiz dos es:" << m;
cout << "-";
cout << "" << m2;
cout << "i" << endl;
}
}
}
return 0;
}
// The following implements type conversion functions.
string toString (double value) { //int also
stringstream temp;
temp << value;
return temp.str();
}
int toInt (string text) {
return atoi(text.c_str());
}
double toDouble (string text) {
return atof(text.c_str());
}
Valora esta pregunta


0