First commit
This commit is contained in:
3
IUT/Info1/TD/Exercices/6.8.1_polynome/.md
Normal file
3
IUT/Info1/TD/Exercices/6.8.1_polynome/.md
Normal file
@@ -0,0 +1,3 @@
|
||||
a=0.011025
|
||||
b=0.21
|
||||
c=1
|
||||
BIN
IUT/Info1/TD/Exercices/6.8.1_polynome/fonction
Normal file
BIN
IUT/Info1/TD/Exercices/6.8.1_polynome/fonction
Normal file
Binary file not shown.
35
IUT/Info1/TD/Exercices/6.8.1_polynome/fonction.cpp
Normal file
35
IUT/Info1/TD/Exercices/6.8.1_polynome/fonction.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include "fonction.h"
|
||||
using namespace std;
|
||||
|
||||
double calcul_discriminant(double a, double b, double c) {
|
||||
return (b*b - 4 * a * c);
|
||||
}
|
||||
void calcul_racines(double a, double b, double c) {
|
||||
double discriminant;
|
||||
discriminant = calcul_discriminant(a, b, c);
|
||||
|
||||
if (discriminant >= -pow(10, -10)
|
||||
&& discriminant <= pow(10, -10)
|
||||
) {
|
||||
discriminant = 0;
|
||||
}
|
||||
if (discriminant < 0) {
|
||||
cout << "delta = " << discriminant << endl;
|
||||
return;
|
||||
} else if (discriminant == 0) {
|
||||
double x0 = (-b/ (2*a));
|
||||
|
||||
cout << "delta = " << discriminant << endl;
|
||||
cout << "La racines est " << x0 << endl;
|
||||
return;
|
||||
}
|
||||
double x1;
|
||||
double x2;
|
||||
x1 = (-b - sqrt(discriminant)) / (2 * a);
|
||||
x2 = (-b + sqrt(discriminant)) / (2 * a);
|
||||
cout << "delta = " << discriminant << endl;
|
||||
cout << "Les racines sont " << x1 << " " << x2 << endl;
|
||||
return;
|
||||
}
|
||||
3
IUT/Info1/TD/Exercices/6.8.1_polynome/fonction.h
Normal file
3
IUT/Info1/TD/Exercices/6.8.1_polynome/fonction.h
Normal file
@@ -0,0 +1,3 @@
|
||||
double calcul_discriminant(double a, double b, double c);
|
||||
|
||||
void calcul_racines(double a, double b, double discriminant);
|
||||
BIN
IUT/Info1/TD/Exercices/6.8.1_polynome/main
Normal file
BIN
IUT/Info1/TD/Exercices/6.8.1_polynome/main
Normal file
Binary file not shown.
13
IUT/Info1/TD/Exercices/6.8.1_polynome/main.cpp
Normal file
13
IUT/Info1/TD/Exercices/6.8.1_polynome/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "fonction.h"
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
double a, b, c;
|
||||
|
||||
cout << "Entrez a, b, c" << endl;
|
||||
cin >> a >> b >> c;
|
||||
|
||||
calcul_racines(a, b, c);
|
||||
}
|
||||
32
IUT/Info1/TD/Exercices/6.8.1_polynome/main.py
Normal file
32
IUT/Info1/TD/Exercices/6.8.1_polynome/main.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from math import sqrt
|
||||
|
||||
def calcul_delta(a: float, b: float, c: float) -> float:
|
||||
return b**2 - 4*a*c
|
||||
|
||||
def calcul_racines(
|
||||
a: float, b: float, c: float
|
||||
) -> tuple[float|None, float|None]:
|
||||
|
||||
delta = calcul_delta(a, b, c)
|
||||
|
||||
if delta < 0:
|
||||
return (None, None)
|
||||
elif delta == 0:
|
||||
return (-b / (2 * a), None)
|
||||
else:
|
||||
return (
|
||||
(-b - sqrt(delta)) / (2 * a),
|
||||
(-b + sqrt(delta)) / (2 * a)
|
||||
)
|
||||
|
||||
def main():
|
||||
valeurs = input()
|
||||
valeurs = map(float, valeurs.split(" "))
|
||||
|
||||
racines = calcul_racines(*valeurs)
|
||||
|
||||
print(f"Les racines sont {racines}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user