Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. program ejer14(input,output);
  2. procedure validar(var x :longint);
  3. begin
  4. repeat
  5. read(x);
  6. until(x>0);
  7. end;
  8. function invertirNumero(numero:longint):longint;
  9. var suma,dig:longint;
  10. begin
  11. suma:=0;
  12. while numero <>0 do
  13. begin
  14. dig:= numero mod 10;
  15. suma:=suma+dig;
  16. numero:= numero div 10;
  17. end;
  18. invertirNumero:=suma;
  19. end;
  20. function sumaDigitos(numero:longint):longint;
  21. var suma,dig:longint;
  22. begin
  23. suma:=0;
  24. while numero <>0 do
  25. begin
  26. dig:= numero mod 10;
  27. suma:=suma+dig;
  28. numero:= numero div 10;
  29. end;
  30. sumaDigitos:=suma;
  31. end;
  32. function especial(numero:longint):longint;
  33. var aux,inv,sdig:longint;
  34. begin
  35. inv:=invertirNumero(numero);
  36. sdig:=sumaDigitos(numero);
  37. aux:= 3 *inv + sdig;
  38. especial:=aux;
  39. end;
  40. function esEspecial(numero:longint):boolean;
  41. var aux:longint;
  42. begin
  43. aux:=especial(numero);
  44. if aux<> numero then
  45. begin
  46. esEspecial:=false;
  47. end
  48. else
  49. begin
  50. esEspecial:=true;
  51. end;
  52. end;
  53. var numero:longint;
  54. begin
  55. validar(numero);
  56. if esEspecial(numero)=true then
  57. begin
  58. write('SI');
  59. end
  60. else
  61. begin
  62. write('NO');
  63. end;
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement