Advertisement
Qpel

ED1.2 Rasti triženklius skaičius, kurių skaitmenų suma yr

Jan 8th, 2018
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.31 KB | None | 0 0
  1. k=0
  2. for x in 100..999
  3.   n=x
  4.   suma=0
  5.   while n!=0
  6.     p=n%10
  7.     suma+=p
  8.     n=n/10
  9.   end
  10.   dal=0
  11.   for y in 1..suma-1
  12.     if suma%y==0
  13.       dal+=y
  14.     end
  15.   end
  16.   if dal==suma
  17.     puts "#{x} skaiciaus skaitmenu suma yra tobulas skaicius"
  18.     k=k+1
  19.   end
  20. end
  21. puts "Viso tokiu skaiciu yra #{k}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement