0
Can someone tell me about how to find a greater or shorter unit in a number .
in no 4536 . 6 is the largest no and 3 is the smallest one how to find that
4 Réponses
+ 3
Just isolate the digits and then compare for max and min simultaneously.
Eg-
int no = 4555;
int max = no%10, min = no%10;
while(no)
{
d = no%10;
if(d>max) max = d;
if(d<min) min = d;
no/=10;
}
cout<<"In "<<no<<", "<<max<<" is the largest no. and "<<min<<" is the smallest no.";
Or you may use an array to save the digits inside elements and then just use the std::max and std::min to find the max and min. That will however be useful only when you also need the place value of the digit, or some other info.
+ 2
no one is there now
+ 1
thanks a lot the code work for me .
/*but in last the value of no. variable got zero for that may be we use another variable for that*/
😎😎😎
+ 1
@Deepraj Evane
Sorry I thought it was not needed anymore so I forgot to make a copy... 😅