diff --git a/Basic/Count Number of Digits in An Integer/SolutionByPrabsimar.cpp b/Basic/Count Number of Digits in An Integer/SolutionByPrabsimar.cpp new file mode 100644 index 000000000..7458de969 --- /dev/null +++ b/Basic/Count Number of Digits in An Integer/SolutionByPrabsimar.cpp @@ -0,0 +1,32 @@ +//Number of digits in an Integer + +#include +using namespace std; + +int main() +{ + long long int num; + long long int n; + cout << "Enter a positive integer "; + cin >> num; + n=num; + + int c = 0; + while (n > 0) + { + n /= 10; + c++; + } + + if (num >= 0) + { + if (num != 0) + cout << "\n Number of Digits in " << num << " is " << c; + else + cout << "\n Number of Digits in " << num << " is 1"; + + } + else + cout << "\n Not a positive integer"; + return 0; + }