Solução: Problema da simplificação das frações (Bruno Barbosa)

From AdonaiMedrado.Pro.Br
Revision as of 22:16, 5 June 2009 by 189.104.94.192 (Talk)

Jump to: navigation, search
#include <stdio.h>
 
int analisaImprime(int num, int x, int y);
 
int analisaImprime(int num, int x, int y){
	int i;
	i = num;
 
	while((x%i!=0)||(y%i!=0)){
		i--;
	}
	if((x%i == 0)&&(y%i==0))
		printf("%d %d\n", x/i, y/i);
 
	else
		printf("%d %d\n", x, y);
}
 
int main(){
 
	int n, m;
	scanf("%d %d", &n, &m);
 
	while(n || m){ 
 
		if(!n || !m)
			printf("%d %d\n", n, m);
 
		else{
			if(n==m)
				printf("%d %d\n", n/n, m/n);
 
			if(n>m)
				analisaImprime(m , n, m);
 
			if(n<m)
				analisaImprime(n, n, m);  
		}
		scanf("%d %d", &n, &m);
	}
}