Advertisement
Sauka1337

Untitled

Sep 25th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.71 KB | None | 0 0
  1. program var_27_task_2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.SysUtils;
  9.  
  10. var
  11.     I : integer;
  12.     SumOfNumbers : integer;
  13.     N : integer;
  14.  
  15. begin
  16.     N := 0;
  17.     While N <= 0 do
  18.     begin
  19.         try
  20.             WriteLn('Enter the value of n : ');
  21.             ReadLn(N);
  22.         except
  23.         on E: Exception do
  24.             Writeln(E.ClassName, ': ', E.Message);
  25.     end;
  26.  
  27.     if N<=0 then
  28.         begin
  29.             WriteLn('Input Error. Check if the data is correct.');
  30.         end;
  31.     end;
  32.  
  33.     for I := 1 to N do
  34.         SumOfNumbers := SumOfNumbers + ((I-1)+I);
  35.  
  36.     WriteLn('Sum of all numbers = ', SumOfNumbers);
  37.     Writeln('Press <enter> to quit...');
  38.     Readln;
  39. end.
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement