-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraymultiplication-recurrsion.cpp
More file actions
71 lines (66 loc) · 1.32 KB
/
arraymultiplication-recurrsion.cpp
File metadata and controls
71 lines (66 loc) · 1.32 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// replace a[0] by a[1]*a[2] , a[1] by a[2]*a[0] , a[2] by a[0][1]
#include<iostream>
using namespace std;
int x=1;
int array[3]={1,2,3}; //answer= [3*2 , 6*3 , 6*18]
int replace_fun(int *ptr1,int *ptr2,int q);
int replace_fun(int *ptr1,int *ptr2,int y,int x);
int main()
{
int *ptr,*ptr1;
ptr=array;
ptr1=(array+3)-1;
replace_fun(ptr,ptr1,3);
for(int i=0;i<3;i++)
{
cout<<array[i]<<endl;
}
}
int replace_fun(int *ptr1,int *ptr2,int y,int x)
{
int q=0;
if(ptr1==ptr2 and ptr2==(array+2))
{
ptr2--;
}
if(y==0)
{
return true;
}
else
{
*ptr1=*ptr2*x;
q=*ptr1;
ptr2--;
y--;
if(ptr2==array-1)
{
//cout<<"here";
return true;
}
else if(ptr1==ptr2 and ptr1==array)
{
//cout<<"true"<<endl;
return true;
}
else if(ptr1==ptr2 and ptr1!=array)
{
//cout<<ptr2--;
ptr2--;
return replace_fun(ptr1,ptr2,y,q);
}
return replace_fun(ptr1,ptr2,y,q);
}
}
int replace_fun(int *ptr1,int *ptr2,int q)
{
if(q==0)
{
return true;
}
replace_fun(ptr1,ptr2,3,x);
ptr1++;
ptr2=(array+3)-1;
q--;
return replace_fun(ptr1,ptr2,q);
}