Разбор задания 6.1. :
В таблице
A
представлены данные о количестве голосов, поданных за
10 исполнителей народных песен (
A[1]
— количество голосов, поданных за первого исполнителя,
A[2]
— за второго и т. д.).
Определите, какое число будет напечатано в результате работы следующей программы.
Текст программы приведён на нескольких языках программирования:
Паскаль:
var k, m: integer;
A: array[1..10] of integer;
Begin
A[1] := 36; A[2] := 20;
A[3] := 20; A[4] := 41;
A[5] := 15; A[6] := 21;
A[7] := 28; A[8] := 17;
A[9] := 15; A[10] := 35;
m := 1;
for k := 1 to 10 do
if A[k] <= A[m] then
begin
m := k;
end;
writeln(m);
End. |
var k, m: integer;
A: array[1..10] of integer;
Begin
A[1] := 36; A[2] := 20;
A[3] := 20; A[4] := 41;
A[5] := 15; A[6] := 21;
A[7] := 28; A[8] := 17;
A[9] := 15; A[10] := 35;
m := 1;
for k := 1 to 10 do
if A[k] <= A[m] then
begin
m := k;
end;
writeln(m);
End.
Бейсик:
DIM A(10) AS INTEGER
DIM k,m AS INTEGER
A(1) = 36: A(2) = 20
A(3) = 20: A(4) = 41
A(5) = 15: A(6) = 21
A(7) = 28: A(8) = 17
A(9) = 15: A(10) = 35
m = 1
FOR k = 1 TO 10
IF A(k) <= A(m) THEN
m = k
ENDIF
NEXT k
PRINT m |
DIM A(10) AS INTEGER
DIM k,m AS INTEGER
A(1) = 36: A(2) = 20
A(3) = 20: A(4) = 41
A(5) = 15: A(6) = 21
A(7) = 28: A(8) = 17
A(9) = 15: A(10) = 35
m = 1
FOR k = 1 TO 10
IF A(k) <= A(m) THEN
m = k
ENDIF
NEXT k
PRINT m
Python:
A= [36, 20, 20, 41, 15, 21, 28, 17, 15, 35]
m = 1
for k in range (10):
if A[k] <= A[m]:
m = k
print (m) |
A= [36, 20, 20, 41, 15, 21, 28, 17, 15, 35]
m = 1
for k in range (10):
if A[k] <= A[m]:
m = k
print (m)
C++:
#include <iostream>
using namespace std;
int main() {
int A[10] = {36, 20, 20, 41, 15, 21, 28, 17, 15, 35};
int m = 1;
for (int k = 0; k < 10; k++)
if (A[k] <= A[m]) m = k;
cout << m;
return 0;
} |
#include <iostream>
using namespace std;
int main() {
int A[10] = {36, 20, 20, 41, 15, 21, 28, 17, 15, 35};
int m = 1;
for (int k = 0; k < 10; k++)
if (A[k] <= A[m]) m = k;
cout << m;
return 0;
}