void function cannot divide integers over 99

-1

When i give it 1011 and 100 i recieve this message: "Process returned -1073741676 (0xC0000094) execution time : 4.425 s" I have got no idea for the life of me why if i give it 99 and 100 it works and it shows 0 but if i give it 100 it starts giving the message above, it should tell me how many of the numbers in n divide k.

#include<iostream>
using namespace std;
void cate(int n,int k,int &x){
    int u=n%10;
    while(n){
        if(k%u==0) x++;
        n/=10;u=n%10;
    }
}
int n,k,x;
int main()
{
    cin>>n>>k;
    cate(n,k,x);
    cout<<x;
}
c++
asked on Stack Overflow Mar 3, 2021 by Cis Pop • edited Mar 3, 2021 by ilkkachu

1 Answer

7
u=n%10;

When n is divisible by 10, u is zero.

k%u

When u is zero, the behaviour of the program is undefined.

answered on Stack Overflow Mar 3, 2021 by eerorika

User contributions licensed under CC BY-SA 3.0