Icosikaienneagonal Number In C++ - C++ Programming Tutorial
C++ Course / Miscellaneous / Icosikaienneagonal Number In C++

Icosikaienneagonal Number In C++

BLUF: Mastering Icosikaienneagonal Number In C++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Icosikaienneagonal Number In C++

C++ is renowned for its efficiency. Learn how Icosikaienneagonal Number In C++ enables low-level control and high-performance computing in the tutorial below.

A polygon with 21 sides is referred to as an isosikaienneagonal shape. The formula P21(k) = k.(19k−17)/2 is used to determine the kth number in this sequence, starting with 1, 21, 62, 124, and so on. Implementing this concept in C++ involves creating a function that can calculate the kth icosikaienneagonal number. Employing a loop is beneficial for generating a series of polygonal numbers up to a specific value. This mathematical formula not only aids in computational problem-solving but also provides insights into number theory, highlighting the correlation between mathematics and programming.

Formulae:

The formula for calculating the kth icosikaienneagonal number is as shown below:

Example

P<sub>21</sub> (k) = k.(19k−17)/2

Where k is the sequence's position (1, 2, 3,...).

Sequence example:

The formula specifies that the initial icosikaienneagonal values are 1, 21, 60, 118, 195, 291, 406, 540, 693, and 865.

Algorithm:

Step 1: Start

Step 2: Enter n (representing the quantity of terms to produce).

Step 3: Set the value of k to 1 in order to start generating numbers starting from the initial position.

Step 4: Repeat the following steps until k>n:

Compute the kth number in the series of Icosikaienneagonal numbers by applying the following mathematical formula:

P 21 (k) = k.(19k−17)/2

Step 4.2: Output P 21 (k).

Step 4.3: Increment k by 1 (k=k+1).

Step 5: End.

Example working:

Assume that n=10

  • K=1: P 21 (1)=1.(19.1-17)/2=1
  • K=2: P 21 (2)=2.(19.2-17)/2=21
  • K=3: P 21 (3)=3.(19.3-17)/2=60
  • K=4: P 21 (4)=4.(19.4-17)/2=118
  • K=5: P 21 (5)=5.(19.5-17)/2=195
  • K=6: P 21 (6)=6.(19.6-17)/2=291
  • K=7: P 21 (7)=7.(19.7-17)/2=406
  • K=8: P 21 (8)=8.(19.8-17)/2=540
  • K=9: P 21 (9)=9.(19.9-17)/2=693
  • K=10: P 21 (10)=10.(19.10-17)/2=865
  • Example 1:

Let's consider an example to demonstrate the Icosikaienneagonal Number concept in C++.

Example

#include <iostream>
using namespace std;
// Function to calculate the k-th Icosikaienneagonal Number
int icosikaienneagonalNumber(int k)
 {
    return (k * (19 * k - 17)) / 2;
}
int main()
 {
    int n; // Number of terms to display
    cout << "Enter the number of Icosikaienneagonal Numbers to generate: ";
    cin >> n;
    cout << "The first " << n << " Icosikaienneagonal Numbers are: ";
    for (int i = 1; i <= n; ++i) {
        cout << icosikaienneagonalNumber(i) << " ";
    }
    cout << endl;
    return 0;
}

Output:

Output

Enter the number of Icosikaienneagonal Numbers to generate: 100
The first 100 Icosikaienneagonal Numbers are: 1 21 60 118 195 291 406 540 693 865 1056 1266 1495 1743 2010 2296 2601 2925 3268 3630 4011 4411 4830 5268 5725 6201 6696 7210 7743 8295 8866 9456 10065 10693 11340 12006 12691 13395 14118 14860 15621 16401 17200 18018 18855 19711 20586 21480 22393 23325 24276 25246 26235 27243 28270 29316 30381 31465 32568 33690 34831 35991 37170 38368 39585 40821 42076 43350 44643 45955 47286 48636 50005 51393 52800 54226 55671 57135 58618 60120 61641 63181 64740 66318 67915 69531 71166 72820 74493 76185 77896 79626 81375 83143 84930 86736 88561 90405 92268 94150

Compile and running:

  • Save the application as icosikaienneagonal.cpp.
  • Use a C++ compiler to compile the code (for example, g++ icosikaienneagonal.cpp -o icosikaienneagonal).
  • Run the application (./icosikaienneagonal).
  • Working:

  • Input: The user selects how many phrases they want.
  • Function: The icosikaienneagonalNumber function applies the formula to find the number.
  • Loop: The program iterates through the values of k, computing each one.
  • Output: The numbers show up sequentially.
  • Example 2:

Let's consider a different example to explain the Icosikaienneagonal Number concept in C++.

Example

#include <iostream>
#include <vector>
using namespace std;
// Function to calculate the k-th Icosikaienneagonal Number
int calculateIcosikaienneagonal(int k) {
    return (k * (19 * k - 17)) / 2;
}
int main() {
    int n; // Number of terms to generate
    cout << "Enter the number of Icosikaienneagonal Numbers to generate: ";
    cin >> n;
    // Vector to store the numbers
    vector<int> icosikaienneagonalNumbers;
    // Calculate and store the numbers
    for (int i = 1; i <= n; ++i) {
        icosikaienneagonalNumbers.push_back(calculateIcosikaienneagonal(i));
    }
    // Display the numbers
    cout << "The first " << n << " Icosikaienneagonal Numbers are: ";
    for (int num : icosikaienneagonalNumbers) {
        cout << num << " ";
    }
    cout << endl;
    return 0;
}

Output:

Output

Enter the number of Icosikaienneagonal Numbers to generate: 10
The first 10 Icosikaienneagonal Numbers are: 1 21 60 118 195 291 406 540 693 865

Explanation:

  • Dynamic Vector Storage: A vector is used to store the results, making expansion and retrieval simple. It offers a versatile method for handling the calculated sequence's memory.
  • Different Calculation Function: The calculateIcosikaienneagonal function contains the computation logic for improved modularity and reusability.
  • Loop for Calculation Iteratively: Values are calculated iteratively and stored in the vector by the loop.
  • Increased Output: The sequence is presented in an orderly and structured way by the program.
  • Conclusion:

In summary, the concept of Icosikaienneagonal Numbers, also known as 21-sided polygonal numbers, illustrates the intriguing overlap between mathematics and programming. By utilizing the equation P 21 (k) = k.(19k−17)/2, one can effortlessly generate these numbers to explore their distinct characteristics and progression. This process is implemented in C++ to showcase the translation of mathematical formulas into functional code that facilitates real-time calculations and the visualization of intricate patterns. Whether utilizing loops, functions, or dynamic data structures such as vectors, these implementations not only enhance our comprehension of number theory but also exemplify the adaptability of programming in resolving mathematical challenges and scrutinizing numerical sequences.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience