Final direction after visiting every cell of Matrix starting from ( 0 , 0 ) | C ++ program to find the direction when stopped moving ; Function to find the direction when stopped moving ; Driver Code ; Given size of NxM grid ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findDirection ( int n , int m ) { if ( n > m ) { if ( m % 2 == 0 ) printf ( " Up STRNEWLINE " ) ; else printf ( " Down STRNEWLINE " ) ; } else { if ( n % 2 == 0 ) printf ( " Left STRNEWLINE " ) ; else printf ( " Right STRNEWLINE " ) ; } } int main ( ) { int n = 3 , m = 3 ; findDirection ( n , m ) ; return 0 ; }