917. Twice the minimum
An array of real numbers is given. Compute
the twice value of the minimum element in the array.
Input. The first line contains the number of elements in the
array n (n ≤ 100). The second line contains n real
numbers, each with an absolute value not exceeding 100.
Output. Print the twice value of the minimum element in the
array with two decimal places.
Sample
input |
Sample output |
6 6 7.5 2.1
2.0 0 -3 |
-6.00 |
arrays
Algorithm analysis
Using a loop, find the
minimum element of the array min. Then print its twice value.
Algorithm implementation
Read
the input data. Compute the
minimum element min of the array.
scanf("%d", &n);
min = 100;
for (i = 0; i < n; i++)
{
scanf("%lf", &a);
if (a < min) min = a;
}
Print the answer – the twice value of the minimum element.
printf("%.2lf\n", 2 * min);
Python implementation
Read
the input data.
n = int(input())
lst = list(map(float, input().split()))
Compute
the minimum element of the list lst.
mn = min(lst)
Print the answer – the twice value of the minimum element.
print(2 * mn)