From 0b8799a6df7f8f0948e6cb8b86d41f412fd9e73f Mon Sep 17 00:00:00 2001 From: Prabsimar-singh <115685692+Prabsimar-singh@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:15:53 +0530 Subject: [PATCH] SolutionByPrabsimar.cpp --- .../SolutionByPrabsimar.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Basic/Count Number of Digits in An Integer/SolutionByPrabsimar.cpp 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; + }