要点1.分式输入时分别输入分母分子,用两个变量分别保存;

要的2.求公约数的方法主要有4种,1.辗转相除法、2.穷举法、3.更相减损法、4.Stein算法,本次采用辗转相除法;

#include<stdio.h>
main()
{
int a,b,div,temp,c,d;
printf("please input numerator denominator respectively\n");
scanf("%d %d",&a,&b);
c=a,d=b;
while(1)
{
temp=c%d;
if(!temp) break;
c=d;
d=temp;
div=d;
}
printf("the greatest common divisor is %d\n",div);
printf("resualt is %d/%d",a/div,b/div);
}

相关文章:

  • 2021-09-23
  • 2022-01-09
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-02-22
猜你喜欢
  • 2021-11-08
  • 2021-10-18
  • 2022-12-23
  • 2021-10-02
  • 2021-11-30
相关资源
相似解决方案