c语言问题。大家帮帮忙!!!

[复制链接]
查看11 | 回复3 | 2007-4-22 12:03:27 | 显示全部楼层 |阅读模式
#include void LeastCommonMultiply(int m, int n);int main(int argc, char* argv[]){ for(;;) {int m = 0, n = 0;printf("请输入整数m: \b");scanf("%d",&m);getchar();printf("请输入整数n: \b");scanf("%d",&n);if (m == 0 || n == 0){
printf("m与n不能为~.\n");}if (mn) ? m : n;int b = (m > n) ? n : m; int c = 0; while ((a % b) != 0) {c = a % b;a = b;b = c; } printf("%d与%d的最大公约数为:%d\n",m,n,b);printf("%d与%d的最小公倍为:%d\n\n",m,n,(m * n / b));}
回复

使用道具 举报

千问 | 2007-4-22 12:03:27 | 显示全部楼层
#includemain(){ int a,b,num1,num2,temp; printf("please input two numbers:\n"); scanf("%d,%d",&num1,&num2); if(num1<num2){ temp=num1;num1=num2; num2=temp; }a=num1;b=num2;while(b!=0)/*利用辗除法,直到b为0为止*/ {temp=a%b;a=b;b=temp; }printf("gongyueshu:%d\n",a);printf("gongbeishu:%d\n",num1*num2/a);}
回复

使用道具 举报

千问 | 2007-4-22 12:03:27 | 显示全部楼层
用递归算法比较简单,但是我忘记细节了。
回复

使用道具 举报

千问 | 2007-4-22 12:03:27 | 显示全部楼层
辗转相除。呵呵
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行