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
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
Use this formula to calculate the height
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; }
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!