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

C/C++ program for triangular matchstick numbers?

王林
Release: 2023-09-23 23:29:01
forward
1468 people have browsed it

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

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

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!

Related labels:
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