CSharp · Console
// The Moscow Ring Road (MKAD) has a length 109 km.
// Biker Ivan starts with “0 km” mark and goes with a constant speed of v km/hour.
// What mark will he pass in t hours?
// The program should input two integer numbers v≠0 and t≥0 and print
// integer number in range 0..108 (the mark where Ivan will be after t hours).
// Negative v means that Ivan goes in opposite direction (0->108->107 etc)
using System;
using System.Diagnostics;
public class Program
{
public static int InputInt(string prompt)
{
Console.Write("Enter " + prompt + ":");
return Convert.ToInt32(Console.ReadLine());
}
public static void Main(string[] args)
{
const int mkad = 109; // The Moscow Ring Road length
// input data
int v = InputInt("the speed");
int t = InputInt("the time");
Trace.Assert(t >= 0);
// calculate (see https://en.wikipedia.org/wiki/Modulo_operation)
int mark = (mkad + (v*t) % mkad) % mkad;
// output result
Console.WriteLine("Ivan will be at mark " + mark);
}
}