How to compute the total number of combinations for choosing 1 out of 3 in a row with 16 rows in C++

3 Answers

0 votes
#include <iostream>
#include <cmath>

int main()
{
    // Number of possible choices in each row
    const int choicesPerRow = 3;

    // Total number of rows
    const int rows = 16;

    // Calculate total combinations: 3^16
    long long totalCombinations = static_cast<long long>(
        std::pow(choicesPerRow, rows)
    );

    // Display the result
    std::cout << "Total lottery combinations: "
              << totalCombinations << std::endl;
}


/*
run:

Total lottery combinations: 43046721

*/

 



answered Oct 19 by avibootz
0 votes
#include <iostream>

int main()
{
    const int choicesPerRow = 3;
    const int rows = 16;

    long long totalCombinations = 1;

    // Multiply by 3 once for each row
    for (int i = 0; i < rows; ++i) {
        totalCombinations *= choicesPerRow;
    }

    std::cout << "Total lottery combinations: "
              << totalCombinations << std::endl;
}


/*
run:

Total lottery combinations: 43046721

*/

 



answered Oct 19 by avibootz
0 votes
#include <iostream>

// Calculates total combinations for:
// choosing 1 option out of 'choicesPerRow'
// across 'rows' rows.
long long calculateCombinations(int choicesPerRow, int rows)
{
    long long total = 1;

    // Multiply choicesPerRow for each row
    for (int i = 0; i < rows; ++i) {
        total *= choicesPerRow;
    }

    return total;
}

int main()
{
    const int choicesPerRow = 3;
    const int rows = 16;

    long long totalCombinations =
        calculateCombinations(choicesPerRow, rows);

    std::cout << "Total lottery combinations: "
              << totalCombinations << std::endl;
}


/*
run:

Total lottery combinations: 43046721

*/

 



answered Oct 19 by avibootz

Related questions

...