Last active
August 29, 2015 13:56
-
-
Save marwein/8933552 to your computer and use it in GitHub Desktop.
PGCD Récursive en utilisant la méthode de soustraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { **************************************************************************** } | |
| { } | |
| { ::: :::::::: } | |
| { pgcd_recursive.pas :+: :+: :+: } | |
| { +:+ +:+ +:+ } | |
| { By: marwein <[email protected]> +#+ +:+ +#+ } | |
| { +#+#+#+#+#+ +#+ } | |
| { Created: 2014/02/11 19:14:10 by marwein #+# #+# } | |
| { Updated: 2014/02/11 19:16:22 by marwein ### ########.fr } | |
| { } | |
| { **************************************************************************** } | |
| PROGRAM PGCD_Reccursive; | |
| USES Wincrt; | |
| VAR | |
| a, b : Integer; | |
| PROCEDURE Saisie (VAR x, y : Integer); | |
| BEGIN | |
| REPEAT | |
| clrscr; {Pour effacer l'ecran avant d'afficher les messages} | |
| writeln('a et b doivent etre superieur a 0'); | |
| write('donner a = '); | |
| readln(x); | |
| write('donner b = '); | |
| readln(y); | |
| UNTIL (x > 0) AND (y > 0) | |
| END; | |
| {Cette fonction pour permuter les valeur de x et y} | |
| PROCEDURE Permutation (VAR x, y : Integer); | |
| VAR | |
| Aux : Integer; | |
| BEGIN | |
| Aux := x; | |
| x := y; | |
| y := Aux; | |
| END; | |
| {PGCD recursive utilisant la methode de soustraction} | |
| FUNCTION PGCD_Rec (x, y : Integer) : Integer; | |
| BEGIN | |
| IF (x = y) THEN | |
| PGCD_Rec := x | |
| ELSE | |
| BEGIN | |
| IF (y > x) THEN | |
| Permutation(x, y); | |
| PGCD_Rec := PGCD_Rec(x - y, y); | |
| END; | |
| END; | |
| BEGIN | |
| saisie(a,b); | |
| writeln('Le PGCD De ', a,' et ', b,' est : ', PGCD_Rec(a,b)); | |
| writeln('[APPUYER SUR UNE TOUCHE POUR QUITTER]'); | |
| Readkey; | |
| {Pour arreter l'affichage jusqu'a ce qu'on appui sur une touche} | |
| END. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment