sjfb.net
当前位置:首页 >> C语言用两个函数求两数最大公约数和最小公倍数 >>

C语言用两个函数求两数最大公约数和最小公倍数

#include#includeint fun_y(int,int);int fun_b(int,int);main(){ int a,b,gy,gb; printf("输入两个整数:\n"); scanf("%d%d",&a,&b); gy=fun_y(a,b); gb=fun_b(a,b); printf("最大公约数是:%d\n最小公倍数是:%d\n",gy,gb);}int fun_y(int x,in...

#include int yue(int m,int n){int i;for(i=n;i>=1;i--)if(m%i==0&&n%i==0)break;return i;}int bei(int m,int n){int i,j;for(i=n;i>=1;i--)if(m%i==0&&n%i==0)break;j=m*n/i;return j;}int main(){int m,n,d,e,t;printf("请输入两个正整数: "...

#include void fun(int m,int n){int a=m,b=n,r;while(b) {r=a%b;a=b;b=r;}printf("\n最大公约数%d\n最小公倍数%d\n",a,m*n/a);}//以上为求两个正整数最大公约数、最小公倍数的函数,以下为主函数void main(){int m,n;scanf("%d%d",&m,&n);fun(m...

(1): #includeint hcf(int a,int b){int c=(ab)?a:b;int m;for(int i=1;i

#include void main( ) { int gongyueshu( int a, int b ); int gongbeishu( int a, int b ); int a, b, c, d; printf("please input two integer numbers:"); scanf("%d%d", &a, &b); c=gongyueshu(a, b); d=gongbeishu(a, b); printf("gongyue...

#include void main( ) { int gongyueshu( int a, int b ); int gongbeishu( int a, int b ); int a, b, c, d; printf("please input two integer numbers:"); scanf("%d%d", &a, &b); c=gongyueshu(a, b); d=gongbeishu(a, b); printf("gongyue...

#includeusing namespace std;int GongYueMax(int a,int b){int i;for (i=a;i>0;i--){if (a%i==0 &&b%i==0){return i;}}return 0;}int GongBeiMin(int a,int b){int i;for (i=a;i>a>>b;cout

#include void main() { int m,n,k,min,max,i; scanf("%d%d",&m,&n); if(n0;i++) { if((m%i==0)&(n%i==0)) { max=i; break; } } min=m*n/max; printf("%d和%d的最大公约数是%d\n",m,n,max); printf("%d和%d的最小公倍数是%d\n",m,n,min); } 这个...

可以给出一定的思路给你: 18, 36 最大公因数 = 18 最小公倍数 = 36 18 = 2 * 9 = 2 * 3 * 3 = 2 * 3^2 36 = 2 * 18 = 2 * 2 * 9 = 2 * 2 * 3 * 3 = 2^2 * 3^2 最大公因数 = 18 = 2 * 3 * 3 = 2 * 3^2 最小公倍数 = 36 = 2 * 2 * 3 * 3 = 2^2 * 3^2

参考代码: #includeint main(){int a, b, num1, num2, temp;printf("输入两个正整数: ");scanf("%d%d", &num1, &num2);if(num1 > num2) { temp = num1;num1 = num2;num2 = temp;} a = num1; b = num2; while(b != 0)/*利用辗除法,直到b为0为止...

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