三角形火柴數的 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