Anderer Ansatz (In der Zwischenzeit getestet und komplett reineditiert) Code: #include <cstdlib> #include <iostream> using namespace std; int max_x, max_y; int anzahlWege(int x, int y) { if(x == max_x && y == max_y) { return 1; } int ret = 0; if(x < max_x) { ret += anzahlWege(x + 1, y); } if(y < max_y) { ret += anzahlWege(x, y + 1); } return ret; } int main(int argc, char *argv[]) { max_x = max_y = 6; cout << "Anzahl Wege: " << anzahlWege(0, 0) << endl; return EXIT_SUCCESS; }
#include <cstdlib> #include <iostream> using namespace std; int max_x, max_y; int anzahlWege(int x, int y) { if(x == max_x && y == max_y) { return 1; } int ret = 0; if(x < max_x) { ret += anzahlWege(x + 1, y); } if(y < max_y) { ret += anzahlWege(x, y + 1); } return ret; } int main(int argc, char *argv[]) { max_x = max_y = 6; cout << "Anzahl Wege: " << anzahlWege(0, 0) << endl; return EXIT_SUCCESS; }
--
Geändert von DFYX (22.03.2007 um 14:32 Uhr)
Foren-Regeln