The task: calculate and print the positive elements that stand in even places C (8) = (-6.3; -1.0; 10.3; -8.8; 6.3; -1.1; 0.0; 0.1) Here is my code:

program laba7_3; const n=5; var m:array[1..n] of integer; k,i,j:integer; Begin writeln('Vvedit massiv'); for i:=1 to n do read(m[i]); for i:=1 to n-1 do for j:=i+1 to n do if (m[j]>m[i]) then begin k:=m[i]; m[i]:=m[j]; m[j]:=k; end; writeln('vidsort mas'); for i:=1 to n do writeln(m[i],' '); readln(m[i]); end. 

But here's the error: Runtime Error: The input string had the wrong format. on the line read (m [i]);

  • I don’t apologize: you need to count the array in descending order: D (5) = (3.2; -6.3; -8.3; 0.0; 1.2), - mishamusha
  • but the code itself fits, I just can't find the error! - mishamusha
  • one
    It remains only to guess how you typed the input string itself ... And, by the way, why do you have an Integer array for real numbers? - alexlz
  • @alexlz: so that's the problem, of course. 3,2 does not parse in Integer . True, it doesn’t take double in double because a comma. - VladD
  • learning tasks do not want someone to fix, sort it out further, if there is a specific problem, then we will help. - vkovalchuk88

1 answer 1

Here in the code there are two lines:

 read(m[i]) 

and

 readln(m[i]); 

The author of the question did not indicate which of them the error popped up.

If the error still pops up in the first case, then most likely it tries to enter floating-point numbers into the integer array. According to his comments, the array should be a real type.

If in the second case, then after the end of the cycle, there is an attempt to enter data into the array m [i] with index i, which is undefined for that case. Then it is not surprising that an error appears there. You should replace this line simply:

 readln; 

So it will be right. The program will wait for the completion of the program by pressing any button.

PS In general, the above code is yours, it solves a completely different task, not at all what you described in the task!