Algorithm 14 - Keep Hydrated!

Beast from the east·2021년 10월 6일
0

Algorithm

목록 보기
14/27

Q.

Description:
Nathan loves cycling.

Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling.

You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value.

For example:

time = 3 ----> litres = 1

time = 6.7---> litres = 3

time = 11.8--> litres = 5

A)

int Liters(double time) 
{
  int drink = 0;
  int save = (int)time;
  drink = save / 2;
  return drink;
}

another solution
int Liters(double time) {
  return (int)(time * 0.5);
}
profile
Hello, Rabbit

0개의 댓글