forked from pclubuiet/Hacktoberfest-2k17
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from shushantkumar/master
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include<stdio.h> | ||
|
||
void main() | ||
|
||
{ | ||
|
||
int n,a[50],i,key,loc,p,q,r,m,fk; | ||
|
||
clrscr(); | ||
|
||
printf("\nenter number elements to be entered"); | ||
scanf("%d",&n); | ||
printf("enter elements"); | ||
for(i=1;i<=n;i++) | ||
scanf("%d",&a[i]); | ||
printf("enter the key element"); | ||
scanf("%d",&key); | ||
fk=fib(n+1); | ||
p=fib(fk); | ||
q=fib(p); | ||
r=fib(q) ; | ||
m=(n+1)-(p+q); | ||
if(key>a[p]) | ||
p=p+m; | ||
loc=rfibsearch(a,n,p,q,r,key); | ||
if(loc==0) | ||
printf("key is not found"); | ||
else | ||
printf("%d is found at location %d",key,loc); | ||
getch(); | ||
} | ||
int fib(int m) | ||
{ | ||
int a,b,c; | ||
a=0; | ||
b=1; | ||
c=a+b; | ||
while(c<m) | ||
{ | ||
a=b; | ||
b=c; | ||
c=a+b; | ||
} | ||
return b; | ||
} | ||
int rfibsearch(int a[],int n,int p,int q,int r,int key) | ||
{ | ||
int t; | ||
if(p<1||p>n) | ||
return 0; | ||
else if(key==a[p]) | ||
return p; | ||
else if(key<a[p]) | ||
{ | ||
if(r==0) | ||
return 0; | ||
else | ||
{ | ||
p=p-r; | ||
t=q; | ||
q=r; | ||
r=t-r; | ||
return rfibsearch(a,n,p,q,r,key); | ||
} | ||
} | ||
else | ||
{ | ||
if(q==1) | ||
return 0; | ||
else | ||
{ | ||
p=p+r; | ||
q=q-r; | ||
r=r-q; | ||
return rfibsearch(a,n,p,q,r,key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
int data[100],n,temp,i,j; | ||
printf("Enter number of terms: "); | ||
scanf("%d",&n); | ||
printf("Enter elements: "); | ||
for(i=0;i<n;i++) | ||
{ | ||
scanf("%d",&data[i]); | ||
} | ||
for(i=1;i<n;i++) | ||
{ | ||
temp = data[i]; | ||
j=i-1; | ||
while(temp<data[j] && j>=0) | ||
{ | ||
data[j+1] = data[j]; | ||
--j; | ||
} | ||
data[j+1]=temp; | ||
} | ||
printf("In ascending order: "); | ||
for(i=0; i<n; i++) | ||
printf("%d\t",data[i]); | ||
return 0; | ||
} |