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

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

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