-
Notifications
You must be signed in to change notification settings - Fork 145
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 #224 from akash-ranjan8/new6
New6
- Loading branch information
Showing
2 changed files
with
47 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,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; | ||
} | ||
|
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,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); | ||
} | ||
|