#C6639. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
Given an array of integers, write a program to compute a new array such that each element at index (i) is the product of all the numbers in the original array except the one at (i). In other words, for an input array (a) of length (n), generate an output array (result) where
[ result[i] = \prod_{\substack{0 \leq j < n \ j \neq i}} a_j ]
Example: For the input array [1, 2, 3, 4, 5], the output should be [120, 60, 40, 30, 24]. This problem must be solved by reading from standard input and writing to standard output.
inputFormat
The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
Output a single line containing (n) space-separated integers that represent the resulting product array.## sample
5
1 2 3 4 5
120 60 40 30 24