编写程序求两个整数的最大公约数和最小公倍数
#include <iostream> using namespace std; int main() { int a, b,c, _a,_b,k; cin >> a >> b; if (a < b) { int t; t = a; a = b; b = t; } _a = a; _b = b; while (_b) { c =_a %_b; _a = _b; _b = c; } cout << "最大公约数为" << _a<<endl; k = a * b / _a; cout << "最小公倍数为" << k<<endl; return 0; }
在主程序中提示输入整数n,编写函数用递归的方法求1+2+3+……+n的值
#include <iostream> using namespace std; int Fun(int _n); int main() { int n,ret; cin >> n; ret=Fun(n); cout << ret << endl; return 0; } int Fun(int _n) { if (_n == 1) { return _n; } else { return _n + Fun(_n - 1); }
标签:13,cout,int,namespace,ret,using,main From: https://www.cnblogs.com/xuechenhao173/p/17398479.html