Calculate the product of all the elements in an array.
Example 1:
Input:
5
1 2 3 4 5
Output:
120
 
Example 2:
Input:
10
5 5 5 5 5 5 5 5 5 5
Output:
9765625
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function product() which takes the array Arr[] and its size N as inputs and returns the product of all elements.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1  ≤  N  ≤  10
1  ≤  A[i]  ≤  5

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def longest(self, arr, n):

        #Code Here

    



Solutions:
class Solution:

	def longest(self, arr, n):
		p = 1
		for i in arr:
			p *= i
		return p


class Solution:

	def longest(self, arr, n):
		a = 1
		for i in range(0, n):
			a *= arr[i]
		return a


class Solution:

	def longest(self, arr, n):
		product = 1
		for i in range(n):
			product *= arr[i]
		return product


class Solution:

	def longest(self, arr, n):
		mult = 1
		for a in arr:
			mult *= a
		return mult


class Solution:

	def longest(self, arr, n):
		prod = 1
		for i in range(len(arr)):
			prod = prod * arr[i]
		return prod


class Solution:

	def longest(self, arr, n):
		acum = 1
		for x in arr:
			acum *= x
		return int(acum)


import functools

class Solution:

	def longest(self, arr, n):
		return functools.reduce(lambda a, b: a * b, arr)


class Solution:

	def longest(self, arr, n):
		prod = 1
		for x in arr:
			prod *= x
		return prod


import numpy

class Solution:

	def longest(self, arr, n):
		return numpy.prod(arr)


class Solution:

	def longest(self, arr, n):
		pro = 1
		for ele in arr:
			pro *= ele
		return pro


import math

class Solution:

	def longest(self, arr, n):
		s = 1
		for i in arr:
			s *= i
		return s


class Solution:

	def longest(self, arr, n):
		c = 1
		for n in arr:
			c *= n
		return c


import numpy as np

class Solution:

	def longest(self, arr, n):
		r = np.prod(arr)
		return r


class Solution:

	def longest(self, arr, n):
		output = 1
		for number in arr:
			output *= number
		return output


class Solution:

	def longest(self, arr, n):
		product = 1
		for num in arr:
			product *= num
		return product


class Solution:

	def longest(self, arr, n):
		su = 1
		for i in arr:
			su = su * int(i)
		return su


import numpy

class Solution:

	def longest(self, arr, n):
		a = numpy.array(arr)
		return numpy.prod(a)


import functools

class Solution:

	def longest(self, arr, n):
		res = functools.reduce(lambda x, y: x * y, arr)
		return res


class Solution:

	def longest(self, arr, n):
		result = 1
		for item in arr:
			result *= item
		return result