COUNT DIGITS CHALLENGE

please give me some hint to solve count digits challenge,

actually i thought of using modulo operation on the integer N but N will vary from 0 to 1000000000 , so i cannot use modulo operator to find the no. of times the digit come in the integer number N ,

will you please give me any hint or share the solution so that i will get a idea solve the question

n is of the range 10^9
and you can use modulo operator on N very easly
there is no problem with %
but you have to store number in long long int

sir but no. vary time to time , sometime no. will be of 3 digits like 254 , sometime it will be of 4 digits, sometimes 5 digits and so on , i dont know what NUMBER N it will be, because no. N is taken from the user , so how to use modulo operation on the no, because every time i have to write different code according to the length of the no N, the code will be too long will you please explain the approach to solve this question

what are you talking??

look at this code

#include <iostream>
using namespace std;
int main() {
    long long int N;
    cin>>N;
    int key; cin>>key;
    int ans=0;
    while(N){
        int digit=N%10;
		N=N/10;
        if(digit==key)ans++;
    }
    cout<<ans<<endl;
}

now if you have any doubt in this code then ask me
it is the correct solution of this question