sábado, 21 de novembro de 2015

EN: Program c++ to calculate the greatest common divisor
 FR: Programme c++ de calculer le plus grand commun diviseur
------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

int main()
{   int aux, max_divisor, value1, value2; 
    printf("\nPT: introduz um numero inteiro\n");
    printf("EN: put a integer number\n");
    printf("FR: tappez un numero entiere\n");
    scanf("%d",&value1);
    printf("\nPT: introduz outro numero\n");
    printf("EN put another integer number\n");
    printf("FR: tappez un autre numero\n");
    scanf("%d",&value2);
    if (value1<value2) aux=value1; else aux=value2;
    for(int it=1; it<= aux ;it++)
    { if ((value1%it ==0)||(value2%it==0))
        printf("\n%d mod %d =%d    %d mod %d =%d",value1, it, value1%it ,value2, it, value2%it);
        if ((value1%it ==0) &&( value2%it==0)) max_divisor=it;
    }
   
    printf("\n\nPT: O maximo divisor comum é %d\n",max_divisor);
    printf("EN: maximum common divisor %d\n",max_divisor);
    printf("FR: diviseur commun maximale %d\n",max_divisor);

    return 0;
}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
the output of the program when i put the integers 100 and 80

100 mod 1 =0    80 mod 1 =0
100 mod 2 =0    80 mod 2 =0
100 mod 4 =0    80 mod 4 =0
100 mod 5 =0    80 mod 5 =0
100 mod 8 =4    80 mod 8 =0
100 mod 10 =0    80 mod 10 =0
100 mod 16 =4    80 mod 16 =0
100 mod 20 =0    80 mod 20 =0
100 mod 25 =0    80 mod 25 =5
100 mod 40 =20    80 mod 40 =0
100 mod 50 =0    80 mod 50 =30
100 mod 80 =20    80 mod 80 =0

PT: O maximo divisor comum é 20
EN: maximum common divisor 20
FR: diviseur commun maximale 20
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

another output
PT: introduz um numero inteiro
EN: put a integer number
FR: tappez un numero entiere
3

PT: introduz outro numero
EN put another integer number
FR: tappez un autre numero
5

3 mod 1 =0    5 mod 1 =0
3 mod 3 =0    5 mod 3 =2

PT: O maximo divisor comum é 1
EN: maximum common divisor 1
FR: diviseur commun maximale 1

Sem comentários:

Enviar um comentário