brewersfan1976

is_sum_of_consecutive_2.rb

Jun 16th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.42 KB | None | 0 0
  1. def isSumOfConsecutive2(n)
  2.     number = 0
  3.     x = 0
  4.     y = 1
  5.     sum = x
  6.    
  7.     while (x < n)
  8.         while (y < n)
  9.               sum = sum + y
  10.                
  11.               if sum == n then
  12.                  number = number + 1
  13.               end
  14.                  
  15.               y = y + 1
  16.         end
  17.            
  18.         x = x + 1
  19.         y = x + 1
  20.         sum = 0
  21.     end
  22.        
  23.     return number
  24. end
Advertisement
Add Comment
Please, Sign In to add comment