-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductOfArray.java
More file actions
40 lines (31 loc) · 843 Bytes
/
ProductOfArray.java
File metadata and controls
40 lines (31 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Given array of integer,return a new array such that each element
at index i of the new array is producd of all the numbers in the original array
except the one at i. you can't use the division
time: O(n)
space: O(n)
i/p: [1,2,3,4,5]
o/p: [120,60,40,30,24]*/
import java.util.*;
public class ProductOfArray
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Size Of Array: ");
int n=sc.nextInt();
System.out.println("Enter the Element of Array: ");
int a1[]=new int[n];
int i;
for(i=0;i<n;i++)
a1[i]=sc.nextInt();
int p=1;
for(i=0;i<n;i++)//find the product of all number
p *=a1[i];
System.out.println("===By Roy ===!Product of given Array: ");
for(i=0;i<n;i++)
{
a1[i]=p/a1[i];
System.out.print(" "+a1[i]+" ");
}
}
}