I have to write a program which displays how many divisors containing the digit "3" does the number entered have. When I introduce a number, nothing happens.
#include <iostream>
usingnamespace std;
int main()
{
int n, d=1, nr=0, x;
cout << "Input a number: "; // so we know what's expected
cin>>n;
while(d<=n)
{
int OK = 0;
if(n%d==0) // so d is a divisor; now, does it have a 3 in ...
{
int divisor = d; // do what coder777 suggested ...
while(divisor!=0) // ...
{
x=divisor%10; // the particular digit
divisor/=10; // ...
if(x==3)
{
OK=1;
}
}
}
if(OK==1) nr++;
d++;
}
cout<<nr;
return 0;
}