Triangular Number API: Calculate and Explore Triangle Numbers

Triangular numbers are figurate numbers that can be arranged in a triangle pattern. The Triangular Number API calculates these numbers, checks if values are triangular, and provides sequence generation - perfect for mathematical applications and educational tools.

What are Triangular Numbers?

Triangular numbers represent the number of dots that can form an equilateral triangle. The nth triangular number is the sum of all positive integers from 1 to n.

Visual representation:

T(1) = 1       *
T(2) = 3       * *
T(3) = 6       * * *
T(4) = 10      * * * *
                

The sequence: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105...

Formula and Properties

Formula

T(n) = n(n+1)/2

This closed-form formula calculates any triangular number instantly without summing all integers.

Interesting Properties

  • Sum of two consecutive triangular numbers is a perfect square
  • Every perfect number is triangular
  • T(n) + T(n-1) = n^2
  • Eight times any triangular number plus one is a perfect square
Connection: The triangular number T(n) represents the number of handshakes when n+1 people all shake hands with each other.

Using the Triangular Number API

TinyFn provides endpoints for triangular number operations:

API Request - Get Nth Triangular
GET https://api.tinyfn.io/v1/math/triangular?n=10
Headers: X-API-Key: your-api-key
Response
{
  "n": 10,
  "triangular_number": 55,
  "formula": "10 * 11 / 2",
  "previous": 45,
  "next": 66,
  "sequence_to_n": [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
}
API Request - Check if Triangular
GET https://api.tinyfn.io/v1/math/triangular/check?number=55
Headers: X-API-Key: your-api-key
Response
{
  "number": 55,
  "is_triangular": true,
  "position": 10,
  "previous_triangular": 45,
  "next_triangular": 66
}

Parameters

Parameter Type Description
n integer Position in sequence (for calculating nth triangular)
number integer Number to check if triangular
include_sequence boolean Include sequence up to n (default: true)

Code Examples

JavaScript / Node.js

// Get the 100th triangular number
const response = await fetch(
  'https://api.tinyfn.io/v1/math/triangular?n=100',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(`T(100) = ${data.triangular_number}`); // 5050

Python

import requests

# Check if 5050 is triangular
response = requests.get(
    'https://api.tinyfn.io/v1/math/triangular/check',
    headers={'X-API-Key': 'your-api-key'},
    params={'number': 5050}
)
data = response.json()
if data['is_triangular']:
    print(f"5050 is T({data['position']})")  # T(100)

cURL

curl "https://api.tinyfn.io/v1/math/triangular?n=10" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Combinatorics: Calculate combinations and arrangements
  • Game Development: Level progression, scoring systems
  • Educational Tools: Teach number sequences and patterns
  • Algorithm Analysis: Analyze O(n^2) complexity growth
  • Puzzle Generation: Create mathematical puzzles

Best Practices

  1. Use the formula: Direct calculation is O(1), iteration is O(n)
  2. Check bounds: Triangular numbers grow quadratically
  3. Explore relationships: Triangular numbers connect to many other sequences
  4. Visualize: The triangle pattern helps understanding
  5. Combine with other checks: Find numbers that are both triangular and square

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-math": {
      "url": "https://api.tinyfn.io/mcp/math/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all math tools available via MCP in our Math MCP Tools for AI Agents guide.

Try the Triangular Number API

Get your free API key and start exploring triangular numbers.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key