Position after taking N steps to the right and left in an alternate manner | C ++ program to find the last coordinate where it ends his journey ; Function to return the last destination ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int lastCoordinate ( int n , int a , int b ) { return ( ( n + 1 ) / 2 ) * a - ( n / 2 ) * b ; } int main ( ) { int n = 3 , a = 5 , b = 2 ; cout << lastCoordinate ( n , a , b ) ; return 0 ; }