mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-07 22:32:28 +08:00
Changes done with codes by adding more comments
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* @author amino19
|
||||
* @file
|
||||
* @file:[Program to count digits in an
|
||||
* integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods)
|
||||
*
|
||||
* \brief Finding number of Digits in a Number
|
||||
* \details Basically, its a very basic math of
|
||||
* finding number of digits in a number (input),
|
||||
* \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 it can be a
|
||||
* positive/negatie value, lets say integer.
|
||||
*
|
||||
* For more details, refer Algorithms-Explanation
|
||||
*/
|
||||
|
||||
@@ -23,14 +27,16 @@ int main() {
|
||||
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) {
|
||||
n /= 10; // n = n/10
|
||||
/* we can also use: n = n/10 */
|
||||
n /= 10;
|
||||
/* each time while loop running, count will
|
||||
* be increment by 1.
|
||||
*/
|
||||
++count;
|
||||
}
|
||||
|
||||
std::cout << "Number of digits: " << count;
|
||||
}
|
||||
Reference in New Issue
Block a user