-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.3.cpp
More file actions
51 lines (49 loc) · 1 KB
/
2.3.cpp
File metadata and controls
51 lines (49 loc) · 1 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
#include<iostream>
using namespace std;
int main(){
int a[100],n,i,c=0,fibm=1,m1=1,m2=0,offset=0,l,s;
cout<<"enter the size of the array"<<endl;
cin>>n;
cout<<"enter the elements"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter the search element"<<endl;
cin>>s;
i=0;
while(fibm<n){
m2=m1;
m1=fibm;
fibm=m1+m2;
}
while(c<=n+1)
{
l=offset+m2;
i = (n>l)?l:n;
if(a[i]==s)
{
cout<<"element found at "<<i+1<<" position"<<endl;
i = -1;
break;
}
else if(a[i]>s)
{
fibm = m2;
m1 = m1-m2;
m2 = fibm-m1;
c++;
}
else
{
fibm = m1;
m1 = m2;
m2 = fibm - m1;
offset =i;
c++;
}
}
if(a[0]==s)
cout<<"element found at 1 position"<<endl;
else if(i!=-1)
cout<<"element not found in the list"<<endl;
return 0;
}