SHARE
TWEET

Untitled

a guest Nov 17th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //fpc 3.0.0
  2.  
  3. program HelloWorld;
  4. (* x ^ y function *)
  5. function pow(x: real; y : real) : real;
  6. begin
  7.     if (x = 0)
  8.     then
  9.         pow := 0
  10.     else
  11.         pow := exp(y * ln(x));
  12. end;
  13. (* end function*)
  14.  
  15. (* return count of chars in number *)
  16. function lenght(x: longint) : integer;
  17. var counter : integer;
  18. begin
  19.     counter := 0;
  20.    
  21.     while x > 9 do
  22.     begin
  23.         x := x div 10;
  24.         counter := counter + 1;
  25.     end;
  26.     counter := counter + 1;
  27.     lenght := counter;
  28. end;
  29. (* end function*)
  30.  
  31. function armstrongNumber(x : longint) : longint;
  32. var numbersCount : integer;
  33. var numberItterator : integer;
  34. var simpleNumber : byte;
  35. var calculatedNumber : longint;
  36. begin
  37.     numbersCount := lenght(x);
  38.     calculatedNumber := 0;
  39.     for numberItterator := 1 to numbersCount do
  40.     begin
  41.         simpleNumber := x mod 10;
  42.         x := x div 10;
  43.         calculatedNumber := calculatedNumber + round(pow(simpleNumber, numbersCount));
  44.     end;
  45.     armstrongNumber := calculatedNumber;
  46. end;
  47.  
  48. (* main function*)
  49. const number = 153;
  50. var armstrongCheckResult : longint;
  51. begin
  52.     armstrongCheckResult := armstrongNumber(number);
  53.     if (armstrongCheckResult = number)
  54.     then
  55.         writeln('this is armstrong number')
  56.     else
  57.         writeln('this is not armstrong number');
  58.     write('inp: ');
  59.     writeln(number);
  60.     write('out: ');
  61.     writeln(armstrongCheckResult);
  62. 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