Home >Backend Development >C++ >C/C++ module equation solution program?

C/C++ module equation solution program?

WBOY
WBOYforward
2023-09-16 18:41:02506browse

We have n coins, and we must use coins to form a pyramid with the maximum height. We arrange the first coin in the first row, the second and third coins in the second row and so on

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

in the given diagram , we use coins with height 3 to make pyramid 6. We cannot make height 4, but we need 10 coins. You can easily get the height using this formula;

H = {(-1 √(1 8N))/2}

Input: n = 10
Output: Height of pyramid: 4

Instructions

Use this formula to calculate the height

H = {(-1 √(1 8N))/2}

Example

#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;
}

The above is the detailed content of C/C++ module equation solution program?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete