三角形火柴数的 C/C++ 程序?
在本文,我们将了解如何计算制作以下金字塔形状所需火柴的数量。金字塔的底座已知。如果底座是 1,那么制作金字塔需要 3 根火柴;底座为 2,需要 9 根火柴;底座为 3,需要 18 根火柴。

要解决此问题,我们必须使用此公式 -

示例
#include <iostream>
using namespace std;
int main(){
int x;
cout << "Enter the size of the base: ";
cin >> x;
int count = 3*x*(x+1)/2;
cout << "Required Matchsticks: " << count;
}输出
Enter the size of the base: 5 Required Matchsticks: 45
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP