Finding the non-zero smallest integer in anumber

Hi.! I'm a beginner .. I encountered a question to find the smallest non-zero digit in a number.. This is my work till now.. I am unable to apply syntax to my logic.. Should i proceed with this and if i should please help me complete the code.. Or should i look for another logic


int n;
cin>>n;
int r = n%10;
while(n/=10)
{
r=min(n%10,r);
}
if(r!=0)
{
cout<<r;
}
else
{

}
nah, it doesn't work if the number has a 0 in it, you should check that before reassigning r

other than that the algorithm looks fine
Topic archived. No new replies allowed.