Cod sursa(job #2637376)
| Utilizator | Data | 22 iulie 2020 17:44:52 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
int findGCD (int a, int b) {
if (a < b) {
swap(a, b);
}
while (b != 0) {
int c = b;
b = a % b;
a = c;
}
return a;
}
int main()
{
fstream fin("euclid2.in");
ofstream fout("euclid2.out");
int t;
fin >> t;
for (int test = 1; test <= t ; ++test) {
int a, b;
fin >> a >> b;
fout << findGCD(a, b) << "\n";
}
return 0;
}
