Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Searching/binary search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<iostream>
using namespace std;
int main()
{
int i,n,k,beg=0,end,mid,f=0,ar[100],ele;
cout<<"Enter Your no. of element";
cin>>n;
for(i=0;i<n;i++)
{
cin>>ar[i];
}
end=n-1;
cout<<"Enter element to find=";
cin>>ele;
while(beg<=end)
{
mid=(end+beg)/2;
if(ar[mid]==ele)
{
k=mid+1;
f=1;
break;
}
else if(ar[mid]<ele)
{
beg=mid+1;
}
else
{
end=mid-1;
}
}
if(f==1)
{
cout<<"Your Element is in "<<k<<" position";
}
else
{
cout<<"element not found";

}
return 0;
}
15 changes: 15 additions & 0 deletions Swap-without-third-variable/swap without using 3 variable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter value of a = ";
cin>>a;
cout<<"Enter value of b = ";
cin>>b;
a=a-b;
b=a+b;
a=b-a;
cout<<"After swaping value of a = "<<a<<" and value of b = "<<b;

}