Skip to content

Commit

Permalink
Merge pull request #224 from akash-ranjan8/new6
Browse files Browse the repository at this point in the history
New6
  • Loading branch information
Danushka96 authored Oct 11, 2019
2 parents 93a1e46 + 2a305ed commit 02d8e17
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
33 changes: 33 additions & 0 deletions C++/binary_search_recursive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<iostream>
using namespace std;
int binary_search(int a[],int lb,int ub,int ele)
{ int mid;
if(lb<ub)
{ mid=(lb+ub)/2;
if(a[mid]==ele)
{ return(mid+1);}
else if(a[mid]<ele)
{ return binary_search(a,mid+1,ub,ele);
}
else
{ return binary_search(a,lb,mid-1,ele);
}
}
else
{ return (-1);}
}
int main()
{ int i,n,k;
cout<<"enter the size of array\n";
cin>>n;
int a[n];
cout<<"enter the array elements\n";
for(i=0;i<n;++i)
{ cin>>a[i];}
cout<<"enter the element to be searched\n";
cin>>k;
int z=binary_search(a,0,n-1,k);
cout<<z;
return 0;
}

14 changes: 14 additions & 0 deletions C/sumdigit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
void main()
{ int num,sum,digit;
sum=0;
printf("enter the number\n");
scanf("%d",&num);
while(num!=0)
{ digit=num%10;
sum=sum+digit;
num=num/10;
}
printf("the sum of the number digit is%d\n",sum);
}

0 comments on commit 02d8e17

Please sign in to comment.