pastebin

Paste Search Dynamic
Recent pastes
sum digits in array
  1. program sumdigits_in_array;
  2. type Tmas=array[1..100] of longint;
  3. procedure input(var n:byte;var T:Tmas);
  4. var i:byte;
  5. begin
  6.   readln(n);
  7.   for i:=1 to n do read(T[i]);
  8. end;
  9. procedure swap(var a,b:longint);
  10. var k:longint;
  11. begin
  12.   K:=a;
  13.   a:=b;
  14.   b:=k;
  15. end;
  16. function sum(T:longint):byte;
  17. begin
  18.   T:=abs(T);
  19.   while T<>0 do begin
  20.     Inc(sum,t mod 10);
  21.     T:=T div 10;
  22.   end;
  23. end;
  24. procedure output(var T:Tmas;n:byte);
  25. var i,j:byte;
  26. begin
  27.   for i:=n-1 downto 1 do
  28.     for j:=1 to i do
  29.       if sum(T[j])>sum(T[j+1]) then swap(T[j],T[j+1]);
  30.   for i:=1 to n-1 do
  31.     for j:=1 to i do
  32.       if sum(T[j])=sum(T[j+1]) then
  33.         if T[j]>T[j+1] then swap(T[j],T[j+1]);
  34.   for i:=1 to n do write(T[i],' ');
  35. end;
  36. var n:byte;T:Tmas;
  37. begin
  38.   Input(n,T);
  39.   Output(T,n);
  40.   readln;
  41. end.
Parsed in 0.014 seconds