What about something like the following?
int cifminpar(const int x)
{
if(!x)
return 11;
//recursive call
int minrest=cifminpar(x/10); //min even in the rest of the digits
if(x % 10 % 2 == 0)
return min(minrest , x%10 );
return minrest;
}
It returns 11
if no even digits are found and work as follows and assumes that the initial number is not 0
.
You can easily fix modify it to return -1
on failure and for 0
as input.
0
solved C++ Recursion: Return the smallest even digit of a number