|
|
back to boardWHY ACCESS_VIOLATION??? #include <iostream> using namespace std; void addNumber (int, int, int*); bool searchNumber (int, int*); void main(){ int digit = 0, base = 2; int i = 0, j = 0, min = 1, max = 1, answer = 0; int number[16] = {0}; cin >> digit >> base; number[digit-1] = 1;
for (i = 1; i <= digit; i++){ max *= base; }
min = (max/base); for (j = min; j <= max; j++){
addNumber(0, base, number);
if (searchNumber(digit, number)){ answer++; }; } cout << answer; } void addNumber (int i, int base, int* number){
if ((number[i] + 1) < base){ number[i]++; } else { number[i] = 0; i++; addNumber(i, base, number); } }; bool searchNumber (int digit, int* number){
for (int i = 0; i < (digit-1); i++){ if (number[i] == 0){ if (number[i+1] == 0){ return false; } } } return true; } Thanks. I figured that one out. -nt- |
|
|