Home Blog Python Notes

Given an array arr[] of n integers, construct a Product Array prod[] (of same size) such that prod[i] is equal to the product of all the elements of arr[] except arr[i].

Published:


	print ('-- product array puzzle --')

	arr = [10, 3, 5, 6, 2]
	prod = []

	product = 1

	for data in arr:
	    product = product * data

	for data in arr:
	    prod.append((product / data))

	print (prod)
Comment