Cod sursa(job #329926)

Utilizator Programmer01Mierla Laurentiu Marian Programmer01 Data 8 iulie 2009 01:55:49
Problema Algoritmul lui Euclid Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
// Euclid.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>

int t, a, b, aux;

int main()
{
	FILE *ofile,*ifile;
	
	ifile = fopen("euclid2.out", "w");
	ofile = fopen("euclid2.in", "r");
	fscanf(ofile, "%i", &t);
	for(int i=0; i<t; i++){
		fscanf(ofile, "%i %i", &a, &b);
		if(a<b){
			aux=a;
			a=b;
			b=aux;
		}
		while(b>1){
			aux = a%b;
			a=b;
			b=aux;
		}
		if(b==1) fprintf(ifile,"%i\n",1);
		else fprintf(ifile,"%i\n",a);
	}
	fclose(ofile);
	fclose(ifile);

	return 0;
}