add solution for lab 6

This commit is contained in:
2025-03-12 12:07:37 -04:00
parent 04af78b253
commit 63708b8858
6 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;
int countPaths(int x, int y) {
// if we are at the origin, there is 1 path
if (x == 0 && y == 0) return 1;
int paths = 0;
// Move left if x > 0
if (x > 0) paths += countPaths(x - 1, y);
// Move up if y > 0
if (y > 0) paths += countPaths(x, y - 1);
return paths;
}
int main() {
int start_x, start_y;
cout << "Enter the starting coordinates (x, y): ";
cin >> start_x >> start_y;
int result = countPaths(start_x, start_y);
cout << "Number of paths to the origin: " << result << endl;
return 0;
}