# Thread: Extracting largest and smallest number

1. ## Extracting largest and smallest number

Hey everyone, I'm new to C++ and know how to extract numbers (for example, to extract 1 from 1289371 I need to do modulo 10 [% 10] and I can do it in a while loop with dividing to keep using modulo on the numbers after) but I don't know how to extract a number and then extract the one after and compare to see which one is larger and then do the same thing again and find out which one is smaller and print them both out.

i.e. Input : 783214
prints out: largest number is 8
smallest number is 1

Can anyone help me?
Thanks.

2. Show us the code for what you can do.

Like a program showing all you learnt in this thread -> How to modulo to this digit

3. read the user input as a char array or string and run a loop through it. the first char in the array or string will be set as your min and max then as you iterate through the loop use conditional operators to check whether a number is higher or lower and if it is then reassign max or min depending on what you were testing for the new value.

to convert the char to int you could use
Code:
`int convertchar2int (const char c) { return (int)(c -'0'); }`

Popular pages Recent additions