- 0
Notifications Mark All Read
- Login
- Get Prime
C Program for Maneuvering a cave (TCS Codevita) | PrepInsta
Maneuvering a Cave Problem
Maneuvering a Cave Problem is one of the sample problems of this year TCS CodeVita Season 9 coding competition. It is a 2-D array manipulation problem. Every year before the starting of the competition TCS CodeVita gives out a few sample questions for the students to practice and anticipate the difficulty level and problem solving technique for the competition.
Problem Description
The task is to count all the possible paths from top left to bottom right of a m x n matrix with the constraints that from each cell you can either move only to right or down.
Input:
- First line consists of T test cases. First line of every test case consists of N and M, denoting the number of rows and number of columns respectively.
Output:
- Single line output i.e count of all the possible paths from top left to bottom right of a m x n matrix..
Constraints:
- 1<=T<=100
- 1<=N<=100
- 1<=M<=100
C Code
#include <stdio.h> int calc(int x, int y) ; int main() { int a,b; printf("Enter the number of rows of the matrix : "); scanf("%d",&a); printf("Enter the number of columns of the matrix : "); scanf("%d",&b); printf("%d", calc(a,b)); return 0; } int calc(int x, int y) { if (x == 1 || y == 1)// If there is a singular matrix { return 1; } else { return calc(x - 1, y) + calc(x, y - 1); } }
Output Enter the number of rows of the matrix : 3 Enter the number of columns of the matrix : 3 6
Maneuvering a Cave Problem in Other Coding Languages
Python
To find the solution of Maneuvering a Cave Problem in Python Programming language click on the button below
C++
To find the solution of Maneuvering a Cave problem in C++ Programming language click on the button below:
Java
To find the solution of Maneuvering a cave problem in Java Programming language click on the button below:
nice
Thanks for the appreciation Samarth, we are obliged