Created
May 20, 2012 14:56
-
-
Save salvianoo/2758400 to your computer and use it in GitHub Desktop.
n5 - mdc
This file contains 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
//O maximo divisor comum de dois inteiros é o maior número que divide ambos | |
//sem deixar o resto. Escreva um programa que lê dois inteiros e calcula o seu | |
//máximo divisor comum. | |
#include <iostream> | |
using namespace std; | |
int MDC(int n1, int n2){ | |
int resto; | |
while(n2 != 0){ | |
resto = n1 % n2; | |
n1 = n2; | |
n2 = resto; | |
} | |
return n1; | |
} | |
int main (int argc, char * const argv[]) { | |
int n1, n2; | |
cout << "Informe o primeiro valor: "; | |
cin >> n1; | |
cout << "Informe o segundo valor: "; | |
cin >> n2; | |
cout << "\nO Máximo Divisor Comum de " | |
<< n1 << " e " << n2 << " é " << MDC(n1, n2) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment