TD1 E6
This commit is contained in:
parent
84f95b2e59
commit
934e50885e
28
TP1/E6.c
Normal file
28
TP1/E6.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Calcule la racine carrée de A par récurrence */
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
double a, x;
|
||||
int jmax, j;
|
||||
printf("Saisissez A positif\n");
|
||||
scanf("%lf", &a);
|
||||
if (a <= 0) {
|
||||
printf("On a dit A>0 !\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Combien d'itérations ?\n");
|
||||
scanf("%d", &jmax);
|
||||
if (jmax < 1 || jmax > 50) {
|
||||
printf("Le nombre d'itérations doit être compris entre 1 et 50.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
x = a;
|
||||
for (j = 1; j <= jmax; j++) {
|
||||
x = (x + a/x)/2;
|
||||
printf("La %dème approximation de la racine carrée de %lf est %lf.\n", j, a, x);
|
||||
}
|
||||
printf("%lf\n", x);
|
||||
return 0;
|
||||
}
|
|
@ -21,6 +21,9 @@ E5-1.exe: E5-1.c
|
|||
E5-2.exe: E5-2.c
|
||||
gcc E5-2.c -o E5-2.exe
|
||||
|
||||
E6.exe: E6.c
|
||||
gcc E6.c -o E6.exe
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
clean:
|
||||
|
|
Reference in a new issue