Given a number X which represents the floor of a matchstick pyramid, write a program to print the total number of matchstick required to form a pyramid of matchsticks of x floors.

Examples:

Input : X = 1 Output : 3 Input : X = 2 Output : 9

This is mainly an extension of triangular numbers. For a number X, the matchstick required will be three times of X-th triangular numbers, i.e., (3*X*(X+1))/2

`// C++ program to find X-th triangular ` `// matchstick number ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `numberOfSticks(` `int` `x) ` `{ ` ` ` `return` `(3 * x * (x + 1)) / 2; ` `} ` ` ` `int` `main() ` `{ ` ` ` `cout << numberOfSticks(7); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

84

Please refer complete article on Triangular Matchstick Number for more details!

## Recommended Posts:

- Program for triangular patterns of alphabets
- C/C++ Program to Find the Number Occurring Odd Number of Times
- C Program for Program to find area of a circle
- C Program for Program for array rotation
- Lex Program to remove comments from C program
- C/C++ Program for n-th Fibonacci number
- C/C++ Program for nth multiple of a number in Fibonacci Series
- Program to check if a number belongs to a particular base or not
- Program to convert given number of days in terms of Years, Weeks and Days
- C Program for Number of stopping station problem
- C Program to Print Number series without using any loop
- C++ Program to check Prime Number
- C Program to Check if all digits of a number divide it
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- C Program to Find minimum sum of factors of number
- C Program for Find largest prime factor of a number
- C Program for Number of elements with odd factors in given range
- C Program for Find sum of odd factors of a number
- C Program for efficiently print all prime factors of a given number
- C Program to check Armstrong Number