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 "stdio.h"int gcd(int a,int b){int r;while(r=a%b)a=b,b=r;return b;}int lcm(int a,int b){return a/gcd(a,b)*b;}int main(int argc,char *argv[]){int x,y;printf("Please enter 2 positive integers...\n");if(scanf("%d%d",&x,&y)...

#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 int gcd(int x, int y); ///最大公约数 int lcm(int x, int y); ////最小公倍数 int main() { int a,b; scanf("%d%d",&a,&b); printf("gcd:%d,lcm:%d\n", gcd(a,b),lcm(a,b)); return 0; } int gcd(int x, int y) { int r; do { r=x%y;...

#include int main() { int m,n,t,i; scanf("%d%d",&m,&n); if(m>n) { t=n; n=m; m=t; } for(i=m;i>=2;i--) if(m%i==0&&n%i==0) printf("%d,%d\n",i,m*n/i); return 0; }

#include//求最大公约数函数int gcd(int a,int b){int temp,r; int v; if(a

#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 //求a和b最大公约数: int yue(int a,int b) { int k=1; int t=a>b?b:a;//a大取b,否则取a for(int i=1;i

#include int gcd(int x, int y);int lcm(int x, int y); int main(){ int a,b; scanf("%d%d",&a,&b); printf("gcd:%d,lcm:%d\n", gcd(a,b),lcm(a,b)); return 0;}int gcd(int x, int y){ int r; do { r=x%y; x=y; y=r; } while(r!=0); return x...

输入两个正整数m和n,求其最大公约数和最小公倍数.用辗转相除法求最大公约数 算法描述:m对n求余为a,若a不等于0 则 m 0) { m_cup = m; #include void main (){int m,n,m1,n1,t;printf ("请输入两个数(用空格隔开):");scanf ("%d %d",&m,&n);if (n...

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