-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Ugly Number With Recursion (Addition of Ugly Number Problem #1286) #1424
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
20496dc
Ugly Number Using Recursion (Addition of Ugly Number Problem #1286)
ErzaTitania-2001 119e85f
Update Ugly Number Recursion In Java
ErzaTitania-2001 463677d
PDDI Using Recursion
ErzaTitania-2001 8a3c429
PDDI Using Recursion
ErzaTitania-2001 3be51a4
Add files via upload
ErzaTitania-2001 2c1d983
Update README.md
iamrajiv a22eec3
Update ArmStrongRecursion.java
iamrajiv 47d8110
Update ArmStrongRecursion.java
iamrajiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
// Checking Armstrong number with Recursion | ||
|
||
import java.util.Scanner; | ||
class ArmStrongRecursion | ||
{ | ||
static int p; | ||
public static int armstrong(int i) | ||
{ if(i<10) //base class | ||
return (int)(Math.pow(i,p)); | ||
else | ||
return((int)Math.pow(i%10,p)+armstrong(i/10)); | ||
} | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
System.out.print("N = "); | ||
int n=sc.nextInt(); | ||
p=Integer.toString(n).length(); //calculating the number of digits in the number by converting it into String | ||
|
||
if(n==armstrong(n)) | ||
System.out.println(n+" is an Armstrong number"); | ||
else | ||
System.out.println(n+" is not an Armstrong number"); | ||
} | ||
} | ||
|
||
/* | ||
Sample Input and Output : | ||
N = 153 | ||
153 is an Armstrong number | ||
Space Complexity: O(1) | ||
Time Complexity : O(p) | ||
*/ |
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,48 @@ | ||
//finding nth ugly number using recursion | ||
import java.util.Scanner; | ||
class UglyRecursion | ||
{ | ||
|
||
public static int ugly(int n) | ||
{ | ||
|
||
if (n == 1) //base cases | ||
return 1; | ||
if (n <= 0) | ||
return 0; | ||
if (n % 2 == 0) | ||
return (ugly(n / 2)); | ||
|
||
if (n % 3 == 0) | ||
return (ugly(n / 3)); | ||
|
||
if (n % 5 == 0) | ||
return (ugly(n / 5)); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
public static void main(String args[]) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
System.out.print("N= "); | ||
int n=sc.nextInt(); | ||
int i=1; | ||
while(n>0) | ||
{ if(ugly(i)==1) | ||
n-=1; | ||
i++; | ||
} | ||
System.out.println(i--); //to avoid the last increment,we decrement by one | ||
} | ||
} | ||
|
||
|
||
/* Sample Input | ||
Input: | ||
N = 10 | ||
Output: 12 | ||
Time Complexity : O(n) | ||
Space Complexity : O(1)*/ |
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 @@ | ||
// Checking Armstrong number with Recursion | ||
|
||
import java.util.Scanner; | ||
class ArmStrongRecursion | ||
{ | ||
static int p; | ||
public static int armstrong(int i) | ||
{ if(i<10) //base class | ||
return (int)(Math.pow(i,p)); | ||
else | ||
return((int)Math.pow(i%10,p)+armstrong(i/10)); | ||
} | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
System.out.print("N = "); | ||
int n=sc.nextInt(); | ||
p=Integer.toString(n).length(); //calculating the number of digits in the number by converting it into String | ||
|
||
if(n==armstrong(n)) | ||
System.out.println(n+" is an Armstrong number"); | ||
else | ||
System.out.println(n+" is not an Armstrong number"); | ||
} | ||
} | ||
|
||
/* | ||
Sample Input and Output : | ||
N = 153 | ||
153 is an Armstrong number | ||
Space Complexity: O(1) | ||
Time Complexity : O(p) | ||
*/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite new to GitHub. Sorry for the troubles.
Ugly Problem link : #1286
PDDI Problem link : #1217
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamrajiv @atarax665 when is this pull request going to be resolved? Should I open two new PRs for each code individually?