Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lcm and gcf program of a given interger #135

Merged
merged 4 commits into from
Dec 16, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions SOLUTIONS/lcm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<iostream>
using namespace std;
int main()
{
int a, b, x, y, temp, hcf, lcm;
cout<<"\n Enter Two Numbers : \n";
cin>>x>>y;
a=x;
b=y;
while(b!=0)
{
temp=b;
b=a%b;
a=temp;
}
hcf=a;
lcm=(x*y)/hcf;
cout<<"\n HCF : "<<hcf<<"\n";
cout<<"\n LCM : "<<lcm<<"\n";
return 0;
}
50 changes: 50 additions & 0 deletions SOLUTIONS/search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>

using namespace std;

int main()
{
int search(int [],int,int);
int n,i,a[100],e,res;
cout<<"How Many Elements:";
cin>>n;
cout<<"\nEnter Elements of Array in Ascending order\n";

for(i=0;i<n;++i)
{
cin>>a[i];
}

cout<<"\nEnter element to search:";
cin>>e;

res=search(a,n,e);

if(res!=-1)
cout<<"\nElement found at position "<<res+1;
else
cout<<"\nElement is not found....!!!";

return 0;
}

int search(int a[],int n,int e)
{
int f,l,m;
f=0;
l=n-1;

while(f<=l)
{
m=(f+l)/2;
if(e==a[m])
return(m);
else
if(e>a[m])
f=m+1;
else
l=m-1;
}

return -1;
}