How to pass an integer with two digits, causing each digit to be in a position in the vector?

1

I make the sum of two numbers 5 and 5, how to pass the result (10) as follows : vetor[0]=1 and vetor[1]=0 , ie separate result for each position of my vector, without the vetor[0] receiving the full value that would be vetor[0]=10 .

    
asked by anonymous 08.06.2016 / 03:42

1 answer

6

Dear,

Using successive division you can separate a decimal. There it is with you to store each digit in the vector: -)

int numero = 520;
while (numero > 0) {
 int algarismo = numero % 10;
 // faça alguma coisa com o algarismo
 numero /= 10;
}
    
09.06.2016 / 05:21