Cod sursa(job #886640)
| Utilizator | Data | 23 februarie 2013 02:33:21 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#include<stdio.h>
long cmmdc(long a, long b)
{ while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;
return a;
}
long t,x,y;
int main()
{
FILE *f;
FILE *g;
f=fopen("euclid2.in","rt");
g=fopen("euclid2.out","wt");
fscanf(f,"%d", &t);
for(long i=1;i<=t;i++)
{
fscanf(f,"%d %d", &x, &y);
fprintf(g,"%d\n",cmmdc(x,y));
}
fclose(f);
fclose(g);
return 0;
}