Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hugo Gallée
- // TP2/exo11.c
- // Calculer une racine carree grace a l'algorithme de Heron d'Alexandrie
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h> // Utilie pour la valeur absolue (abs) et la fonction sqrt
- int main()
- {
- int a, i, n;
- float x, xNext;
- printf("Calculer la racine carre de : ");
- a = lire_entier(a);
- printf("Precision : 1/");
- n = lire_entier(n);
- x = a;
- xNext = (x / 2.) + ((float) a / (2. * x));
- while (abs(x - xNext) > 1. / n) {
- x = xNext;
- xNext = (x / 2.) + ((float) a / (2. * x));
- }
- printf("\n");
- printf(" xNext: %4.5f\n", xNext);
- printf("sqrt(%d): %4.5f\n", a, sqrt((float) a));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement