Advertisement
Guest User

Lab1

a guest
Apr 8th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.26 KB | None | 0 0
  1. uses
  2.   System.SysUtils;
  3.  
  4. var
  5.   arr: array of integer;
  6.  
  7.   I,J, N, sum: integer;
  8.  
  9. begin
  10. Write('N = ');
  11. ReadLn(N);
  12.  
  13. SetLength(arr, N);
  14. {Заполнение массива числами от 0 до N (не включая)}
  15. for I := 0 to N - 1 do
  16.   arr[i]:= i;
  17.  
  18.   WriteLn('1st task');
  19.  
  20.    for I := 0 to N - 1 do
  21.    begin
  22.      if(arr[I] mod 2 = 0) then WriteLn(arr[I]);
  23.    end;
  24.  
  25.  WriteLn('2nd task');
  26.  
  27.    for I:= N - 1 downto 0 do
  28.    begin
  29.      if(arr[I] mod 2 <> 0) then WriteLn(arr[I]);
  30.    end;
  31.  
  32.  WriteLn('3rd task');
  33.  
  34.    for I := 0 to N - 1 do
  35.    begin
  36.     if(arr[I] mod 2 = 0) then
  37.     begin
  38.       WriteLn(arr[I]);
  39.     end;
  40.     if (I = N - 1) then
  41.       begin
  42.         for J := N - 1 downto 0 do
  43.         begin
  44.           if(arr[J] mod 2 <> 0) then WriteLn(arr[J]);
  45.         end;
  46.       end;
  47.    end;
  48.  
  49.   WriteLn('4th task');
  50.  
  51. sum:=0;
  52. j:=0;
  53.    for I := 0 to N - 1 do
  54.    begin
  55.      if(arr[I] mod 3 = 0) then
  56.      begin
  57.       WriteLn(arr[I]);
  58.       sum:= sum + arr[i];
  59.       j:= j + 1;
  60.      end;
  61.    end;
  62. WriteLn(sum, ' - Sum');
  63. WriteLn(j, ' - Count');
  64.  
  65.   WriteLn('5th task');
  66.  
  67. sum:=0;
  68. j:=0;
  69.   for I := 0 to N - 1 do
  70.    begin
  71.     j:= j + 1;
  72.     sum:= sum + arr[i];
  73.    end;
  74.    WriteLn('Average - ' , sum / j);
  75.    ReadLn;
  76. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement