第四周项目(1)-求最大公约数
来源:互联网 发布:分型指标源码 编辑:程序博客网 时间:2024/05/24 06:37
/*
*copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:hellow.cpp
*作者:田甜
*完成日期:2016年3月23日
*版本号:v1.0
*
*问题描述:输出四个整数的最大公约数
*输入描述:输入四个整数
*程序输出:输出所输四整数的最大公约数
*/
问题及代码:
#include <iostream>using namespace std;int gcd(int x,int y);int gcds(int a,int b,int c,int d);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){ if(!y) return x; return gcd(y,x%y);}int gcds(int a,int b,int c,int d){ int m,n; n=gcd(a,b); m=gcd(c,d); return gcd(m,n);}
运行结果:
知识点总结:
函数的递归调用。
学习心得:
练习熟练掌握函数的递归调用。
0 0
- 第四周项目(1)-求最大公约数
- 第四周项目1求最大公约数
- 第四周项目1:求最大公约数
- 第四周项目1:求最大公约数
- 第四周【项目1-求最大公约数】
- 第四周项目1-求最大公约数
- 第四周项目1-求最大公约数
- 第四周项目1-求最大公约数
- 第四周项目1-求最大公约数
- 第四周项目1-求最大公约数
- 第四周项目1:求最大公约数
- 第四周项目1-求最大公约数
- 第四周项目1-求最大公约数(1)
- 第四周项目1——(1)求最大公约数
- 第四周项目1-求最大公约数(1)
- 第四周项目1-求最大公约数(1)
- 第四周项目1-求最大公约数(2)
- 第四周项目1-求最大公约数(3)
- 百钱买百鸡
- 第四周【递归函数求出n的阶乘】
- nginx+tomcat+memcached搭建服务器集群及负载均衡
- Liunx系统定时任务时间设置Crontab的格式
- 最大公约数计算
- 第四周项目(1)-求最大公约数
- Redis中JedisPool基本使用
- 项目12--程序分析
- 第四周项目四 程序分析(问题3)
- 第四周项目1-求最大公约数
- 【NWERC2015】【BZOJ4426】BetterProductivity最大生产率
- nginx配置
- 第三周项目三输出星号图
- 第四周【求1*3*...*n的递归式】