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

2nd Dec 2017, 5:16 PM
Deepraj Evane
Deepraj Evane - avatar
4 Answers
+ 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.
2nd Dec 2017, 5:23 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
no one is there now
2nd Dec 2017, 5:17 PM
Sachin Lobo Jeppu
Sachin Lobo Jeppu - avatar
+ 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*/ 😎😎😎
2nd Dec 2017, 5:43 PM
Deepraj Evane
Deepraj Evane - avatar
+ 1
@Deepraj Evane Sorry I thought it was not needed anymore so I forgot to make a copy... 😅
2nd Dec 2017, 5:58 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar