-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductArray_Except_Self.cpp
More file actions
53 lines (41 loc) · 964 Bytes
/
Copy pathProductArray_Except_Self.cpp
File metadata and controls
53 lines (41 loc) · 964 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> ProductArray(int *arr, int n)
{
int i;
vector<int> left(n, 0);
vector<int> right(n, 0);
left[0] = 1;
for(i=1; i<n; i++)
left[i] = left[i-1]*arr[i-1];
right[n-1] = 1;
for(i=n-2; i>(-1); i--)
right[i] = right[i+1]*arr[i+1];
for(i=0; i<n; i++)
left[i] = left[i]*right[i];
return left;
}
int main()
{
int t;
cout<<"\nEnter the Testcases: ";
cin>>t;
while(t)
{
int n, i;
cout<<"\nEnter the Size of the Array: ";
cin>>n;
int arr[n];
cout<<"Enter the Array Elements: ";
for(i=0; i<n; i++)
cin>>arr[i];
cout<<"Resultant Array: ";
vector<int> res;
res = ProductArray(arr, n);
for(auto it=res.begin(); it != res.end(); it++)
cout<<*it<<" ";
cout<<"\n";
return 0;
}
}