View Code of Problem 66

#include<stdio.h>

int gcd(int a,int b)
{
	int c,t;
	if(a<b)
	{
		t = a; a = b; b = t;
	}
	c = a%b;//m=a*b
	while(c!=0)
	{
		a=b;
		b=c;
		c=a%b;
	}
	return b;//m/bΪ×îС¹«±¶Êý 
}

int main()
{
	int a,b;
	while( scanf("%d %d",&a,&b)!=EOF )
	{
		if(a==b)
		{
			printf("1\n");
		}
		else
		{
			printf("%d/%d\n",a/gcd(a,b),b/gcd(a,b));
		}	
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 66