- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipilcation.cpp
More file actions
Latest commit
38 lines (34 loc) · 620 Bytes
/
Copy pathmultipilcation.cpp
File metadata and controls
38 lines (34 loc) · 620 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
#include<limits.h>
#include<iostream>
usingnamespacestd;
/*leetcode.com/2010/04/multiplication-of-numbers.html*/
voidmultiplication(int *a, int *o, int n)
{
int left = 1;
int right = 1;
for (int i = 0; i <n ; ++i)
{
o[i] *= left;
o[n - i - 1] *= right;
left *= a[i];
right *= a[n - i - 1];
}
}
// Driver program to test above functions
intmain()
{
int l[5] = {4,3,2,1,2};
int o[5] = {1,1,1,1,1};
int n = sizeof(l)/sizeof(l[0]);
multiplication(l, o, n);
for (int i = 0; i <n ; ++i)
{
cout<<l[i] << "";
}
cout<<endl;
for (int i = 0; i <n ; ++i)
{
cout<<o[i] << "";
}
return0;
}