Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Starting in the top left corner of a 2 times 2 grid, and only being able to move

ID: 3792928 • Letter: S

Question

Starting in the top left corner of a 2 times 2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. Compute the number of these types of routes through an n times n grid for 1 lessthanorequalto n lessthanorequalto 20. Allow the user to choose n Inputs the size of the grid (ie: n = 10 where the grid is n times n) Output: the number (of routes from the top left corner to the bottom right corner) Extra Credit: Repeat the question but where n may be any positive integer.

Explanation / Answer

#include <iostream>
using namespace std;
int numberOfPaths(int m, int n)
{
if (m == 1 || n == 1)
return numberOfPaths(m-1, n) + numberOfPaths(m, n-1);
}
int main()
{
   cout>> "Size of grid: ";
   cin << n;
cout << numberOfPaths(n, n);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote