
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C/C++ Program for the Triangular Matchstick Number?
A triangle that is made by using matchsticks arrange to make an equilateral triangle, this is called the triangular matchstick number. Triangular matchstick number is the number of matchsticks required to make the matchstick triangle.
In this problem, we have the number is the floor of a matchstick pyramid, X. and our task is to write a program to print the total minimum number of matchstick required to form a pyramid of matchsticks of x floors.
Let's look at an example that will make the concept more clear,
Input: 7 Output: 84
Explanation
This is an extension of triangular numbers. For integer X, the matchstick required will be three times of X-th triangular numbers , i.e., (3*X*(X+1))/2
Example
#include <iostream> using namespace std; int main() { int x=7; cout<<(3 * x * (x + 1)) / 2; return 0; }
- Related Articles
- C/C++ Program for Triangular Matchstick Number?
- Python Program for Triangular Matchstick Number
- Program for triangular patterns of alphabets in C
- C++ Program for triangular pattern (mirror image around 0)
- C++ code to check triangular number
- Find the fifth triangular number.
- C# Program to Illustrate Lower Triangular Matrix
- C# program to Illustrate Upper Triangular Matrix
- Program to print Lower triangular and Upper triangular matrix of an array in C
- C++ Program to Print the Multiplication Table in Triangular Form
- First triangular number whose number of divisors exceeds N in C++
- C/C++ Program for the n-th Fibonacci number?
- C/C++ Program for Finding the Number Occurring Odd Number of Times?
- C/C++ Program for nth Catalan Number?
- C Program for nth Catalan Number

Advertisements