TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
[Program to count digits in an integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods) More...
#include <cassert>
#include <cmath>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Functions | |
uint64_t | finding_number_of_digits_in_a_number (uint64_t n) |
for log calculation | |
double | finding_number_of_digits_in_a_number_using_log (double n) |
This function finds the number of digits in constant time using logarithmic function TC: O(1) | |
static void | first_test () |
Self-test implementations. | |
static void | second_test () |
int | main () |
Main function. | |
[Program to count digits in an integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods)
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). The code for that is also included (finding_number_of_digits_in_a_number_using_log). For more details, refer to the Algorithms-Explanation repository.
Definition in file finding_number_of_digits_in_a_number.cpp.
uint64_t finding_number_of_digits_in_a_number | ( | uint64_t | n | ) |
for log calculation
for assert for IO operations
The main function that checks the number of digits in a number. TC : O(number of digits)
n | the number to check its digits |
< the variable used for the digits count
Definition at line 31 of file finding_number_of_digits_in_a_number.cpp.
double finding_number_of_digits_in_a_number_using_log | ( | double | n | ) |
This function finds the number of digits in constant time using logarithmic function TC: O(1)
n | the number to check its digits |
Definition at line 54 of file finding_number_of_digits_in_a_number.cpp.
|
static |
Self-test implementations.
Definition at line 74 of file finding_number_of_digits_in_a_number.cpp.
int main | ( | void | ) |
Main function.
Definition at line 97 of file finding_number_of_digits_in_a_number.cpp.
|
static |
Definition at line 84 of file finding_number_of_digits_in_a_number.cpp.