Tuesday, 28 July 2020

Count Number of Digits of an Integer in C++

                Count Number of Digits of an Integer in C++


This code is simple to write Count Number of Digits of an Integer in C++




#include <iostream>
using namespace std;
int main() {
    int num, temp;
    int count = 0;
    cout << "Enter any number : ";
    cin >> num;
    temp = num;   
    while(temp != 0) {
        count++;
        temp /= 10;
    }
    cout << endl << "Number of digits in " << num << " : "  << count;
    return 0;
}



Output



Enter any number : 34657

Number of digits in 34657: 5

No comments:

Post a Comment