4025约分

#include<stdio.h>
int main()
{
    
    
	int a, b, c, ys;
	int fun (int x,int y);
	scanf("%d %d",&a,&b);	
	if(a%b==0)
	{
    
    
			printf("%d",a/b);
			return 0;
	}
	if(a>=b)
	{
    
    
			c=a/b;
			ys=fun(a-c*b,b);
			printf("%d+%d/%d",c,(a-c*b)/ys,b/ys);
	}	
	if(a<b)
	{
    
    
		ys=fun(a,b);
		printf("%d/%d",a/ys,b/ys);	
	}	
	return 0;
 } 


 //辗转相除法
 int fun (int x,int y)
 {
    
    
 	int i,temp;
 	if(x<y)
 	{
    
    
 		temp=x;
 		x=y;
 		y=temp;
	}
	i=x%y;
 	while(i)
 	{
    
    
 		x=y;
 		y=i;
 		i=x%y;
	}
 	return y;    //i为x,y最大公约数 ,x>y 
 }

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_51333166/article/details/113902239