92.1k views
5 votes
A car can cover distance of N kilometers per day. How many days will it take to cover a route of length M kilometers? The program gets two numbers: N and M. Utilize a function days (n,m) that returns the number of days to cover the route. Restrictions: No math methods or if statements may be used. Example input 700 750 Example output

User Webmasters
by
7.7k points

2 Answers

2 votes

Final answer:

To calculate the number of days to cover a route of length M kilometers, divide M by N. Example calculation included.

Step-by-step explanation:

To calculate the number of days it will take to cover a route of length M kilometers, we can use the formula: days = M / N. Here, M represents the length of the route and N represents the number of kilometers the car can cover per day. By dividing the length of the route by the number of kilometers covered per day, we can determine the number of days it will take to cover the entire route.

For example, if the car can cover 700 kilometers per day and the route is 750 kilometers long, we would divide 750 by 700 to find that it will take approximately 1.07 days to cover the entire route.

User Suslik
by
8.1k points
4 votes

Final answer:

To calculate the number of days it will take to cover a route of length M kilometers by a car that can cover N kilometers per day, divide the distance by the car's speed.

Step-by-step explanation:

To calculate the number of days it will take to cover a route of length M kilometers, we need to divide the distance by the car's speed.

The speed of the car is given as N kilometers per day. Therefore, the number of days it will take to cover the route is given by:

Number of days = M / N

For example, if the car covers a distance of 700 kilometers per day and the route length is 750 kilometers, it will take:

Number of days = 750 / 700 = 1.071

Since we cannot have a fraction of a day for this calculation, we can round up to the nearest whole number. Therefore, it will take the car approximately 2 days to cover the route.

User Sali
by
8.1k points

No related questions found