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
using System ; class GFG { public static int lastCoordinate ( int n , int a , int b ) { return ( ( n + 1 ) / 2 ) * a - ( n / 2 ) * b ; } public static void Main ( string [ ] args ) { int n = 3 , a = 5 , b = 2 ; Console . WriteLine ( lastCoordinate ( n , a , b ) ) ; } }