Cod sursa(job #1018319)
| Utilizator | Data | 29 octombrie 2013 12:41:02 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *citire,*scriere;
citire = fopen("euclid2.in", "r");
scriere = fopen("euclid2.out","w");
int a,b,n;
fscanf(citire,"%d",&n);
for(;n>0;n--)
{fscanf(citire,"%d",&a);
fscanf(citire,"%d",&b);
if(a>0&&b>0)
while(a>1&&b>1)
if(a>b)
a=a%b;
else if(b>a)
b=b%a;
if(a==1||b==1)
fprintf(scriere,"%d\n",1);
else
fprintf(scriere,"%d\n",b);
}
return 0;
}
