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;
}
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.
User contributions licensed under CC BY-SA 3.0