实际上的真分数化简的问题,计算公约数,怎么使用C语言谢谢

Problem Description
Find the fraction closest to sqrt(N), the denominator of the fraction is no more than M.

Input
The input consists of multiple test cases.For each case the input contains two integers N and M, 1<=N<=1000000, 1<=M<=1000.

Output
For each case output one line, contaning the fraction that in the form "A/B" where A and B are positive integers with no common factors greater than one.

Sample Input
9 4

Sample Output
3/1

1.输入
2.求出N的算术平方根得N1
3.分数分子为N1*M,分母为M
4.约分,分子分母同除以最大公约数
5.输出

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

typedef struct fraction
{
    int numerator;
    short denominator;
}fraction;

void reduation(fraction* fract)
{
    int x=fract->numerator,y=fract->denominator;
    while(y!=0)
    {
        int z=x%y;
        x=y,y=z;
    }
    fract->numerator/=x,fract->denominator/=x;
    return;
}

int main(void)
{
    fraction fract={0,0};
    scanf("Input N:%d",&fract.numerator);
    scanf("Input M:%hd",&fract.denominator);
    if(!(1<=fract.numerator&&fract.numerator<=1000000))
    {
        puts("Error Input N");
        return 1;
    }
    if(!(1<=fract.denominator&&fract.denominator<=1000))
    {
        puts("Error Input M");
        return 1;
    }
    fract.numerator=sqrt(fract.numerator)*(double)fract.denominator;
    reduation(&fract);
    printf("%d/%hd\n",fract.numerator,fract.denominator);
    return 0;
}

https://blog.csdn.net/momo_mo520/article/details/80534752