实验5-8:求最小公倍数和最大公约数(简单循环结构) 输入两个整数m和n,用辗转相除法求两个数的最小公倍数和最大公约数。 输出格式:the greatest common divisor:%d\nthe minimum common multiple:%d\n
4 6
the greatest common divisor:2 the minimum common multiple:12 | 10.00 |
#include<stdio.h>
int main()
{int a,b,i;int yueshu,beishu;scanf("%d%d",&a,&b);for( i=a; i>=1;i--){if(a%i==0 && b%i==0){yueshu = i;break;}}for(i = a;;i++){if(i%a==0 && i%b==0){beishu = i;break;}}printf("the greatest common divisor:%d\nthe minimum common multiple:%d\n",yueshu,beishu);return 0;}
得分10.00 最后一次提交时间:2023-04-10 19:36:36 成功编译,但有警告信息. Main.c: In function 'main': Main.c:33:11: warning: 'yueshu' may be used uninitialized in this function [-Wmaybe-uninitialized] printf("the greatest common divisor:%d\nthe minimum common multiple:%d\n",yueshu,beishu); ^ 共有测试数据:2 平均占用内存:1.211K 平均CPU时间:0.00248S 平均墙钟时间:0.00248S
详细 |
有警告,但无妨,能跑就行。