Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // apple xcode
- // paulogp
- /* algoritmo de euclides (mdc) */
- #include <stdio.h>
- // metodo recursivo
- int func_mdc_r (int the_n1, int the_n2)
- {
- return(the_n2 > 0 ? func_mdc_r(the_n2, the_n1 % the_n2): the_n1);
- }
- // metodo iteractivo
- int func_mdc_i (int the_n1, int the_n2)
- {
- int the_temp;
- while (the_n2 > 0)
- {
- the_temp = the_n2;
- the_n2 = the_n1 % the_n2;
- the_n1 = the_temp;
- }
- return the_n1;
- }
- int main (int argc, const char * argv[])
- {
- /* mdc: maximo divisor comum algoritmo de Euclides */
- int the_n1, the_n2, the_result;
- printf("Introduza N1: ");
- scanf("%i", &the_n1);
- printf("Introduza N2: ");
- scanf("%i", &the_n2);
- the_result = func_mdc_i(the_n1, the_n2);
- printf("result i: %i\n", the_result);
- the_result = func_mdc_r(the_n1, the_n2);
- printf("result r: %i\n", the_result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement