human
Sum of all perfect numbers present in an array | Function to return the sum of all the proper factors of n.
f is the factor of n.
Function to return the required sum.
To store the sum.
If current element is non - zero and equal to the sum of proper factors of itself.
Driver code"
Solution in Python:
assistant
#Here is code to sum of all perfect numbers present in an array and the other steps required.
 def sumOfFactors ( n ) :
	sum = 0
	for f in range ( 1 , n // 2 + 1 ) :
		if ( n % f == 0 ) :
			sum += f
	return sum
def getSum ( arr , n ) :
	sum = 0
	for i in range ( n ) :
		if ( arr [ i ] > 0 and arr [ i ] == sumOfFactors ( arr [ i ] ) ) :
			sum += arr [ i ]
	return sum
arr = [ 17 , 6 , 10 , 6 , 4 ]
n = len ( arr )
print ( getSum ( arr , n ) )