您好,欢迎访问一九零五行业门户网

C/C++ 模块方程解的程序?

我们有 n 枚硬币,我们必须用硬币的方式来组成最大高度的金字塔。我们将第一个硬币安排在第一行,第二个和第三个硬币安排在第二行,依此类推
在给定的图中,我们用高度为 3 的硬币制作金字塔 6。我们不能制作高度 4,但我们需要 10 个硬币。使用这个公式可以很简单地得到高度;
h = {(-1+ √(1+8n))/2}
input: n = 10output: height of pyramid: 4
说明使用此公式计算高度
h = {(-1+ √(1+8n))/2}
示例#include <iostream>#include <math.h>using namespace std;int main() { int n=10; int height = (-1 + sqrt(1 + 8 * n)) / 2; cout << "height of pyramid: " <<height;}
以上就是c/c++ 模块方程解的程序?的详细内容。
其它类似信息

推荐信息