Advertisement
informaticage

lungth num

Jun 3rd, 2021
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int lunghezza_numero(int numero) {
  6.   int lunghezza = 0;
  7.   if (numero == 0) return 1;
  8.  
  9.   while (numero != 0) {
  10.     numero = numero / 10;
  11.     lunghezza = lunghezza + 1;
  12.   }
  13.  
  14.   return lunghezza;
  15. }
  16.  
  17. int main() {
  18.   int x;
  19.   cout << "N: ";
  20.   cin >> x;
  21.   cout << "Lunghezza: " << lunghezza_numero(x) << endl;
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement