C语言分数相加并将最后结果化为最简分式(新手程序!!!)

【问题描述】输入两个分数,对两个分数相加求和,要求和为最简分式。(两个分数为正数)
【输入形式】3/24,5/36
【输出形式】19/72
【样例输入】1/7,4/21
【样例输出】1/3
源代码如下:

#include 
	int main()
	{
   int x1,x2,y1,y2,z1,z2,j,k,i;
	    scanf("%d/%d,%d/%d",&x1,&x2,&y1,&y2);
	    z2 = x2 * y2;
 	    z1 = x1 * y2 + x2 * y1;
	    j = z1;
 	    k = z2;
 	    do
 	    {
 	        i = z2 % z1;
 	        
 	        if(i != 0)
	        {
 	            z2 = z1;
 	            z1 = i;
	        }
 	        else
 	            break;
 	    }
 	    while(i != 0);
 	    j = j / z1;
 	    k = k / z1;
	    if(k != 1)
	    printf("%d/%d",j,k);
	    else
 	    printf("%d",j);
 	    return 0;
	}
	
 

你可能感兴趣的:(C语言分数相加并将最后结果化为最简分式(新手程序!!!))