daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program LAB12;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Windows,
  7.   SysUtils;
  8.  
  9. var
  10.   Number, i, PlusOrMinus, Sum, EvenOrOdd : Integer;
  11.   IsCorrect : Boolean;
  12.  
  13. begin
  14.    SetConsoleCP(1251);
  15.    SetConsoleOutPutCP(1251);
  16.    Writeln('Çäðàâñòâóéòå, äàííàÿ ïðîãðàììà ñ÷èòàåò çíàêîïåðåìåííóþ ñóììó öèôð çàäàííîãî âàìè ÷èñëà');
  17.    IsCorrect := False;
  18.    repeat
  19.       Writeln('Ââåäèòå ÷èñëî (äàííîå ÷èñëî äîëæíî áûòü íàòóðàëüíûì è äîëæíî áûòü íå áîëüøå 2147483647): ');
  20.       try
  21.          Readln(Number);
  22.          IsCorrect := True;
  23.       except
  24.          on E: EInOutError do
  25.             Writeln('Âû ââåëè íåâîçìîæíîå ÷èñëî! Ïîæàëóéñòà ââåäèòå ââåðíîå ÍÀÒÓÐÀËÜÍÎÅ ÷èñëî');
  26.             end;
  27.    until IsCorrect;
  28.    EvenOrOdd := length(IntToStr(Number)) mod 2;
  29.    Sum := 0;
  30.       if EvenOrOdd = 0 then
  31.          begin
  32.          PlusOrMinus := -1;
  33.          for i := 1 to Length(IntToStr(Number)) do
  34.          begin
  35.             Sum := Sum + PlusOrMinus * ((Number mod 10));
  36.             Number := Number div 10;
  37.             PlusOrMinus := PlusOrMinus * (-1)
  38.          end;
  39.          end
  40.       else
  41.          begin
  42.          PlusOrMinus := 1;
  43.          for i := 1 to Length(IntToStr(Number)) do
  44.          begin
  45.             Sum := Sum + PlusOrMinus * ((Number mod 10));
  46.             Number := Number div 10;
  47.             PlusOrMinus := PlusOrMinus * (-1)
  48.          end;
  49.          end;
  50.  
  51.    Writeln('Çíàêîïåðåìåííàÿ ñóììà öèôð çàäàííîãî âàìè ÷èñëà ðàâíÿåòñÿ ', IntToStr(Sum));
  52.    Readln;
  53. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top