用辗转相除法求两个整数M和N的最大公约数和最小公倍数,用While循环,循环变量i,

用辗转相除法求两个整数M和N的最大公约数和最小公倍数,用While循环,循环变量i,
#include "stdio.h"
#include "math.h"
#include "conio.h"
#include "stdlib.h"
void NONO( int m,int n,int s1,int s2);
main()
{ int m=9,n=84,s1,s2,r;
//
printf("The highest common divisor of %d and %d is %dn",m,n,s1);
printf("The lowest common multiple of %d and %d is %dn",m,n,s2);
NONO(m,n,s1,s2);
}
void NONO(int m,int n,int s1,int s2)
{ FILE *f;
f=fopen("out1.dat","w");
fprintf(f,"%d,%d,%dn",m,n,s1);
fprintf(f,"%d,%d,%dn",m,n,s2);
fclose(f);
}
求修补
江师 1年前 已收到1个回答 举报

shijko 幼苗

共回答了18个问题采纳率:100% 举报

循环变量应该是r吧,
你这里都没有定义i怎么使用?可以自己定义吗?
int a=m;
int b=n;
while(m!=0)/*利用辗除法,直到m为0为止*/   
{   
r=n%m;   
n=m;   
m=temp;   
}   
s1 = n;
s2 = a*b/s1; //最小公倍数等于 两个数的乘积除以最大公约数.

1年前

3
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.163 s. - webmaster@yulucn.com