Cod sursa(job #837218)

Utilizator krissu93FMI Tiugan Cristiana Elena krissu93 Data 17 decembrie 2012 18:28:15
Problema Algoritmul lui Euclid Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.43 kb
#include <stdio.h>


long cmmdc(long a, long b)
{
	if(a==0) return b;
	else
	if (b==0) return a;	
	else
	{
	if (a>b) return cmmdc(a%b,b);
		else return cmmdc(a,b%a);
	}
}

int main()
{
	long n,a,b;
	FILE *fin, *fout;
fin=fopen("euclid2.in","r"); 
fout=fopen("euclid2.out","w"); 

fscanf(fin,"%Ld",&n); 
for (int i=1;i<=n;i++)
{
	fscanf(fin,"%Ld%Ld",&a,&b);
	fprintf(fout,"%Ld\n",cmmdc(a,b));
}
return 0;
}