Home > Backend Development > C++ > body text

C/C++ module equation solution program?

WBOY
Release: 2023-09-16 18:41:02
forward
481 people have browsed it

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
Copy after login

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;
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template