-
-
Notifications
You must be signed in to change notification settings - Fork 7.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
feat: Finding no. of digits in a Number #1497
Merged
Merged
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6f2e300
Finding no. of digits in a Number
aminoxix aa968b6
Initialize n
aminoxix 38df5b7
Initialize n as int
aminoxix d5b3040
Changes done
aminoxix 53c56b8
Changes done with codes by adding more comments
aminoxix 60cefcf
Changes done with codes by adding name as md
aminoxix fe6b55b
Modified comments
aminoxix 1214af0
add void
aminoxix 8ec7cef
remove void & update comments
aminoxix 4fb644b
Set some changes to pass Awesome CI Workflow
aminoxix 8fc28d8
add return 0 & file name in lower case
aminoxix d4b955e
Changes done..
aminoxix 27e0b69
Update finding_number_of_Digits_in_a_Number.cpp
aminoxix ed9caec
Update finding_number_of_Digits_in_a_Number.cpp
aminoxix 1b1eea7
Update finding_number_of_Digits_in_a_Number.cpp
aminoxix 0ec45e3
Merge branch 'master' into aminos
Panquesito7 585df61
formatting filenames 0ec45e33
c997114
updating DIRECTORY.md
3854f43
clang-format and clang-tidy fixes for 0ec45e33
9c0a437
Merge branch 'master' into aminos
aminoxix 79dd94e
clang-format and clang-tidy fixes for 9c0a437e
3af026a
Merge branch 'master' into aminos
Panquesito7 4ef7da0
Merge branch 'master' into aminos
Panquesito7 857f01d
updating DIRECTORY.md
75c0e35
Wrote test, needs review
aminoxix 7d7ff37
Merge branch 'master' into aminos
aminoxix 78540d2
Merge branch 'master' into aminos
Panquesito7 dd7ab31
[fix/docs]: Fix tests/code and add documentation
Panquesito7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @author [aminos 🇮🇳](https://github.com/amino19) | ||
* @file | ||
* | ||
* @brief [Program to count digits | ||
* in an integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods) | ||
* @details It is a very basic math of finding number of digits in a given | ||
* number i.e, we can use it by inputting values whether it can be a | ||
* positive/negative value, let's say: an integer. There is also a second method: | ||
* by using "K = floor(log10(N) + 1)", but it's only applicable for | ||
* numbers (not integers). | ||
* For more details, refer to the [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/en/Basic%20Math/Finding the number of digits in a number.md) repository. | ||
*/ | ||
|
||
#include <cassert> /// for assert | ||
#include <iostream> /// for IO operations | ||
|
||
/** | ||
* @brief Main function | ||
* @returns 0 on exit | ||
*/ | ||
int main() { | ||
// Initialize `n` & `count` by 0 | ||
int n = 0; | ||
int count = 0; | ||
|
||
std::cout << "Enter an integer: "; | ||
std::cin >> n; | ||
|
||
// iterate until `n` becomes 0 | ||
// remove last digit from `n` in each iteration | ||
// increase `count` by 1 in each iteration | ||
while (n != 0) { | ||
// we can also use `n = n / 10` | ||
n /= 10; | ||
// each time the loop is running, `count` will be incremented by 1. | ||
++count; | ||
} | ||
std::cout << "Number of digits: " << count; | ||
|
||
aminoxix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; | ||
} |
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.
Please add self-test implementations using
assert
(see the typical structure of a program as an example).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.
@Panquesito7 : Help me for this! 😄
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 don't know if I can help you, as you understand better your algorithm and your program, so you should be able to do it. However, if you have any doubts, let me know.🙂
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.
@Panquesito7 : Yep, for sure, you're right! :)