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

feat: Finding no. of digits in a Number #1497

Merged
merged 28 commits into from
Sep 3, 2021
Merged
Changes from 11 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 May 25, 2021
aa968b6
Initialize n
aminoxix May 25, 2021
38df5b7
Initialize n as int
aminoxix May 25, 2021
d5b3040
Changes done
aminoxix May 25, 2021
53c56b8
Changes done with codes by adding more comments
aminoxix May 25, 2021
60cefcf
Changes done with codes by adding name as md
aminoxix May 26, 2021
fe6b55b
Modified comments
aminoxix May 26, 2021
1214af0
add void
aminoxix May 26, 2021
8ec7cef
remove void & update comments
aminoxix May 26, 2021
4fb644b
Set some changes to pass Awesome CI Workflow
aminoxix May 26, 2021
8fc28d8
add return 0 & file name in lower case
aminoxix May 26, 2021
d4b955e
Changes done..
aminoxix May 26, 2021
27e0b69
Update finding_number_of_Digits_in_a_Number.cpp
aminoxix Jun 1, 2021
ed9caec
Update finding_number_of_Digits_in_a_Number.cpp
aminoxix Jun 2, 2021
1b1eea7
Update finding_number_of_Digits_in_a_Number.cpp
aminoxix Jun 3, 2021
0ec45e3
Merge branch 'master' into aminos
Panquesito7 Jul 27, 2021
585df61
formatting filenames 0ec45e33
Jul 27, 2021
c997114
updating DIRECTORY.md
Jul 27, 2021
3854f43
clang-format and clang-tidy fixes for 0ec45e33
Jul 27, 2021
9c0a437
Merge branch 'master' into aminos
aminoxix Aug 26, 2021
79dd94e
clang-format and clang-tidy fixes for 9c0a437e
Aug 26, 2021
3af026a
Merge branch 'master' into aminos
Panquesito7 Aug 29, 2021
4ef7da0
Merge branch 'master' into aminos
Panquesito7 Sep 1, 2021
857f01d
updating DIRECTORY.md
Sep 1, 2021
75c0e35
Wrote test, needs review
aminoxix Sep 1, 2021
7d7ff37
Merge branch 'master' into aminos
aminoxix Sep 1, 2021
78540d2
Merge branch 'master' into aminos
Panquesito7 Sep 1, 2021
dd7ab31
[fix/docs]: Fix tests/code and add documentation
Panquesito7 Sep 1, 2021
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
48 changes: 48 additions & 0 deletions math/finding_number_of_Digits_in_a_Number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @author [ANSHUMAAN](https://github.com/amino19)
* @file [Program to count digits in an
* integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods)
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
*
* @brief Finding number of Digits in a Number
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
* @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, lets say integer. There is also second method to do
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
* it with, by using "K = floor(log10(N) + 1)", but its only applicable for
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
* numbers (not integers).
* For more details, refer Algorithms-Explanation
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
*/

#include <cassert> /// for assert
#include <iostream> /// for IO operations

Copy link
Member

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).

Copy link
Member Author

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! 😄

Copy link
Member

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.🙂

Copy link
Member Author

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! :)

/**
* @brief Main function
* @returns 0 on exit
*/
int main() {
/* Initialize 'n' & 'count' by 0 */
int n = 0;
int count = 0;

/* 'cout' to ask input from user..
* 'cin' to taking integer as input..
*/
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "Enter an integer: ";
std::cin >> n;

/* iterate until n becomes 0
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
* 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 while loop running, count will
* be increment by 1.
*/
aminoxix marked this conversation as resolved.
Show resolved Hide resolved
++count;
}

std::cout << "Number of digits: " << count;

aminoxix marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}
Panquesito7 marked this conversation as resolved.
Show resolved Hide resolved
aminoxix marked this conversation as resolved.
Show resolved Hide resolved