Skip to content

Commit

Permalink
Merge pull request #339 from shushantkumar/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mishal23 authored Oct 9, 2017
2 parents 221cca4 + 22f0a01 commit 6eb8726
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Fibonacci_Search/shushantkumar.c
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);
}
}
}
27 changes: 27 additions & 0 deletions Insertion_Sort/shushantkumar.c
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;
}

0 comments on commit 6eb8726

Please sign in to comment.