-
Notifications
You must be signed in to change notification settings - Fork 8k
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 #329 from yamini236/master
lcmreturnrecursion
- Loading branch information
Showing
3 changed files
with
69 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
26 changes: 26 additions & 0 deletions
26
Program's_Contributed_By_Contributors/C++_Programs/factoralrecursion.cpp
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,26 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int factorial(int a){ | ||
int b=0,c=0; | ||
if(a>0){ | ||
b= factorial(a-1); | ||
b=b*a; | ||
return b; | ||
|
||
} | ||
else | ||
{ | ||
return 1; | ||
} | ||
|
||
|
||
|
||
} | ||
int main(){ | ||
int a,x; | ||
cin>>a; | ||
x=factorial(a); | ||
cout<<x; | ||
return 0; | ||
} |
41 changes: 41 additions & 0 deletions
41
Program's_Contributed_By_Contributors/C++_Programs/lcmreturnrecursion.cpp
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,41 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int lcm(int a,int b,int i){ | ||
int p=0; | ||
if(i<=a || i<=b){ | ||
if(a%i==0 && b%i==0){ | ||
p=lcm(a/i,b/i,i); | ||
return p*i; | ||
|
||
} | ||
else if(a%i==0){ | ||
p=lcm(a/i,b,i); | ||
return p*i; | ||
|
||
|
||
} | ||
else if(b%i==0){ | ||
p=lcm(a,b/i,i); | ||
return p*i; | ||
|
||
|
||
} | ||
else{ | ||
p=lcm(a,b,i+1); | ||
return p; | ||
|
||
} | ||
|
||
} | ||
else{ | ||
return 1; | ||
} | ||
} | ||
int main(){ | ||
int a,b,x; | ||
cin>>a>>b; | ||
x=lcm(a,b,2); | ||
cout<<x; | ||
return 0; | ||
} |