第11周项目2-求最大公约数-四数
2014-11-08 22:57
246 查看
/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:C++18.cpp *作 者:王一锟 *完成日期:2014年11月6日 *版 本 号:v1.0 * *问题描述:求四个数的最大公约数 *输入描述:四个整数 *输出描述:四个数的最大公约数 */ #include <iostream> using namespace std; int gcds(int x,int y,int z,int w); int gcd(int x,int y); int main() { int a,b,c,d,g; cin>>a>>b>>c>>d; g=gcds(a,b,c,d); cout<<"最大公约数是:"<<g; return 0; } int gcd(int x,int y) { int z,g; if(x<y) { z=x; x=y; y=z; } while(x%y!=0) { g=x%y; x=y; y=g; } return y; } int gcds(int x,int y,int z,int w) { int i; i=gcd(gcd(x,y),gcd(z,w)); return i; }
输出结果:
函数的嵌套运用。
相关文章推荐
- 第11周 项目2-2 四数的最大公约数
- 第11周项目2-2 求四数的最大公约数。
- 第11周项目--求四数的最大公约数
- 第11周项目2 求最大公约数1
- 十二周上机项目3:四数的最大公约数
- 第11周项目 求两个数的最大公约数
- 第11周项目二 求最大公约数改版
- 第11周项目2-1 求两数的最大公约数
- 第11周项目2-求最大公约数
- 第11周项目二 求最大公约数
- 第11周项目2用函数求最大公约数
- C++第11周项目2——最大公约数
- C++第12周项目3——四数的最大公约数
- 第11周项目2求两个数的最大公约数
- 第11周项目2(2)-求4个数的最大公约数
- 遗漏题目--第11周项目2:求两个数的最大公约数
- 第11周项目2-求最大公约数
- 第11周上机实践项目2——求最大公约数
- 第11周项目2求四个数的最大公约数 .
- 2014秋C++第11周项目2参考-求最大公约数