首页 精品C语言求最大公约数和最小公倍数算法总结

精品C语言求最大公约数和最小公倍数算法总结

举报
开通vip

精品C语言求最大公约数和最小公倍数算法总结精品C语言求最大公约数和最小公倍数算法总结 C C C TP312 A The algorithm summarization of evaluating the highest common divisor and the lowest common multiple in C Language Zhao Ye Lin Tutor TeacherLiu Xiao Hua Introduction to the algorithm basic thought, algorithm process and ...

精品C语言求最大公约数和最小公倍数算法总结
精品C语言求最大公约数和最小公倍数算法总结 C C C TP312 A The algorithm summarization of evaluating the highest common divisor and the lowest common multiple in C Language Zhao Ye Lin Tutor TeacherLiu Xiao Hua Introduction to the algorithm basic thought, algorithm process and code realization and its analysing comparison in terms of evaluating the highest common divisor and the lowest common multiple of any two positive integers by learning to using C Language KeywordsC Language algorithm the highest common divisor the lowest common multiple CC 1 Ca,b a b=0 gcd(a,b) = gcd(b,a mod b) b!=0 , :a,ba ,btemp 1ab 2a/b 3temp=0b 4temp!=0batempa 5 int divisor (int a,int b) /*自定义函数求两数的最大公约数*/ { int temp; /*定义整型变量*/ if(ab)?b:a; /*采种条件运算 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 达式求出两个数中的最小值*/ while(temp>0) { if (a%temp==0&&b%temp==0) /*只要找到一个数能同时被a,b所整除~则中止循环*/ break; temp--; /*如不满足if条件则变量自减~直到能被a,b所整除*/ } return (temp); /*返回满足条件的数到主调函数处*/ } #include "stdio.h" main() { int m,n,t1; printf("please input two integer number:"); scanf("%d%d",&m,&n); t1=divisor(m,n); printf("The higest common divisor is %d\n",t1); getch(); } a,b,abba int multiple (int a,int b) { int p,q,temp; p=(a>b)?a:b; /*求两个数中的最大值*/ *求两个数中的最小值*/ q=(a>b)?b:a; / temp=p; /*最大值赋给p为变量自增作准备*/ while(1) /*利用循环语句来求满足条件的数值*/ { if(p%q==0) break; /*只要找到变量的和数能被a或b所整除~则中止循环*/ p+=temp; /*如果条件不满足则变量自身相加*/ } return (p); } #include "stdio.h" main() { int m,n,t2; printf("please input two integer number:"); scanf("%d%d",&m,&n); t2=multiple(m,n); printf("The least common multiple is %d\n",t2); getch(); } C [1] C 2004 [2] C 2004 [3] C 2002 [4] 2002
本文档为【精品C语言求最大公约数和最小公倍数算法总结】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_977556
暂无简介~
格式:doc
大小:18KB
软件:Word
页数:0
分类:初中语文
上传时间:2017-09-30
浏览量:21