Home >Backend Development >C++ >C/C++ program for triangular matchstick numbers?

C/C++ program for triangular matchstick numbers?

王林
王林forward
2023-09-23 23:29:011380browse

C/C++ program for triangular matchstick numbers?

A triangle with matchsticks arranged to form an equilateral triangle is called a triangle match number. The number of triangle matches is the number of matches required to form a triangle of matches.

In this problem, our number is the base X of the match pyramid. Our task is to write a program that prints the total number of matchsticks required to form a pyramid of x-level matches.

Let us look at an example to make the concept clearer,

Input: 7
Output: 84

Explanation

This is an extension of trigonometric numbers. For an integer X, the number of matchsticks required will be three times the number of triangles in the ##

#include <iostream>
using namespace std;
int main() {
   int x=7;
   cout<<(3 * x * (x + 1)) / 2;
   return 0;
}

The above is the detailed content of C/C++ program for triangular matchstick numbers?. 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