1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <cmath>
using namespace std;
void incrementToValue(int*, int, int, int);
int main()
{
int numVars, // how many variables
highestAmount, // Highest amount a variable can store.
numCombos,
currentNum = 1;
int * combos;
cout << "How many variables: ";
cin >> numVars;
cout << "How many different values [1 < x <= 12]: ";
cin >> highestAmount;
numCombos = (int)(pow(highestAmount, numVars));
combos = new int[numVars];
for (int i = 0; i < numVars; i++)
{
combos[i] = 0; // initialize all vars to zero.
}
for (int i = 0; i < numCombos; i++)
{
incrementToValue(combos, numVars, highestAmount, i);
}
delete[] combos;
return 0;
}
void incrementToValue(int * combos, int numVars, int highestAmount, int numToIncrement)
{
int val;
for (int i = numVars - 1; i >= 0; i--)
{ // 12 / (5^0)
val = (((numToIncrement / (int)(pow(highestAmount, i))) * numVars) % highestAmount);
cout << val + 1 << "\t";
}
cout << endl;
}
|