An array of 3-digit numbers was given, it was necessary to find the sum of digits of each number and arrange them in descending order with their initial addresses. For example, at the beginning was the number 526, stood at the 5th place of the original array, the sum of its numbers is 13, it turned out to be the largest in the new array, but we must indicate its initial place, that is, "was at the 5th place of the original array".
program lab; const n=10; Type MyType=record number:integer; indexPrev:byte; end; Type ArrMyType = array[1..n] of MyType; var i,j: integer; a:array[1..n] of MyType; function f(x:integer):integer; var d,s: integer; begin s:=0; while x > 0 do begin d:= x mod 10; s:= s + d; x:= x div 10; end; f:=s; end; procedure swap(var x,y: integer); var t: integer; begin t := x; x := y; y := t end; begin writeln('Исходный массив'); for i:=1 to n do begin a[i].number:=random(100)+500; a[i].indexPrev:=i; write(i,' эл. = ',a[i].number,' '); end; writeln; writeln('Cумма цифр в числе,без сортировки'); for i:=1 to n do a[i].number := f(a[i].number); for i:=1 to n do write(' y ',i,' эл. = ',a[i].number, ' '); for i:=1 to n-1 do for j:=i+1 to n do if a[i].number < a[j].number then swap(a[i].number,a[j].number); writeln; writeln('Новый массив'); for i:=1 to n do write(a[i],' ','начальный номер = ') //???????????????????????? end. And how to display the initial place?
swapprocedure needs to be changed so that it does not exchange whole numbers, but the entireMyTyperecord - MBowrite(a[i].number,' ','начальный номер = ', a[i].indexPrev);- slippyk