mlfk.net
当前位置:首页 >> C语言编程:输入两个正整数,求最大公约数和最小公... >>

C语言编程:输入两个正整数,求最大公约数和最小公...

main() { int p,r,n,m,temp; printf("Please enter 2 numbers n,m:"); scanf("%d,%d",&n,&m);//输入两个正整数. if(n

#includevoid main(){int a,b,i;scanf("%d %d",&a,&b);for(i=a+b;i>1;i--){if(a%i==0&&b%i==0){printf("最大公约数为%d,最小公倍数为%d\n",i,a*b/i);return 0;}}printf("最大公约数为1,最小公倍数为%d\n",a*b);return 0;} 给你来个最简单的吧

main() { int a,b,num1,num2,temp; printf("请输入两个正整数:\n"); scanf("%d,%d",&num1,&num2); if(num1

代码如下: //有问题可以QQ联系我: 1609299076#include int main() { int m, n, p, tmp; printf("请输入两个正整数:\n"); scanf("%d %d", &m, &n); p = m * n; while (n != 0) { tmp = m % n; m = n; n = tmp; } printf("最大公约数: %d\n", m)...

#include void main () { int m, n, p, q; printf ("请输入整数m,n的值:\n"); scanf ("%d, %d", &m, &n); p=m*n; while (n!=0) { q=m%n; m=n; n=q; //这段是求最大公约数的算法 } printf ("最大公约数是%d\n", m);//上面的算法n=0时m这时的值就...

#include"stdio.h"main(){ int m,n,t,h,a,b,q;printf("输入m,n的值:");scanf("%d%d",&m,&n);a=m;b=n;if (n>m) {t=m;m=n;n=t;}while (m%n!=0){ h=n;n=m%n;m=n;}a=a/n;b=b/n;q=a*b*n;printf("两数最大公约数为 %d,最小公倍数为 %d\n",n,q);}

#include int main() {int a,b,r,lcm,gcd; scanf("%d%d",&a,&b); lcm=a*b; while(r=a%b) {a=b; b=r; } gcd=b; lcm/=gcd; printf("最大公约数=%d\n最小公倍数=%d\n",gcd,lcm); return 0; }

# include void main(){ int m,n,c,x,y; printf("请输入两个正整数,用逗号间隔:"); scanf("%d,%d",&m,&n); x=m; y=n; if (m

#include void main (){ int m,n,m1,n1,t; printf ("请输入两个数(用空格隔开):"); scanf ("%d %d",&m,&n); if (n > m) { t = m; m = n; n = t; } m1 = m; n1 = n; while (n != 0) { t = m%n; m = n; n = t; } printf ("%d 和 %d 的最大公约数...

#includeint main(){ int a,b,g; scanf("%d%d",&a,&b); g=a>b?b:a; while(g>1) if(a%g==0 && b%g==0) break; printf("%d 和%d的最大公约数=%d 最小公倍数=%d\n", a,b, g, a/g*b); return 0;}

网站首页 | 网站地图
All rights reserved Powered by www.mlfk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com