#C13322. Product Except Self
Product Except Self
Product Except Self
Given an array of n integers, your task is to compute a new array such that each element at index i of the output array is equal to the product of all the numbers in the original array except the one at i.
Mathematically, for an input array nums of length n, you need to compute the output array output where:
[ output[i] = \prod_{\substack{0 \leq j < n \ j \neq i}} nums[j] ]
The solution should handle cases where the array contains zeros, negative numbers, or a mix of both.
Note: Do not use the division operation in your solution.
inputFormat
The input will be provided via standard input (stdin) in the following format:
- The first line contains a single integer n, which is the number of elements in the array.
- The second line contains n space-separated integers representing the elements of the array.
outputFormat
The output should be printed to standard output (stdout) as a single line of n space-separated integers. These integers represent the products for each position computed as described in the problem statement.
## sample5
1 2 3 4 5
120 60 40 30 24