Help me in solving PPSCPP87 problem

My issue

this doesn’t give correct answer for number with digits larger than 10.why?

My code

#include <iostream>
using namespace std;

int main() {
    int num, count = 0;
    cin >> num;

    while (num != 0) {
        // Update your code below this line
        num=num/10;
        count+=1;
        
        
    }
    cout << count;
    return 0;
}

Learning course: Introduction to C++
Problem Link: Coding problem - 3 Practice Problem in Introduction to C++ - CodeChef

instead of int num, use long long int num.

1 Like