fork download
  1. # Define the one-dimensional array of real numbers (you can change this array as needed)
  2. arr = [5.2, 3.1, 7.8, 6.5, 4.3]
  3.  
  4. k = 0
  5. indices = []
  6.  
  7. for i in range(len(arr) - 1):
  8. if arr[i] > arr[i + 1]:
  9. k += 1
  10. indices.append(i)
  11.  
  12. print("Indices of numbers greater than their right neighbor:", indices)
  13. print("The number K of such numbers:", k)
Success #stdin #stdout 0.02s 7080KB
stdin
Standard input is empty
stdout
('Indices of numbers greater than their right neighbor:', [0, 2, 3])
('The number K of such numbers:', 3)