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

Asked

Viewed 417 times

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, that is, separate the result for each position of my vector, without the vetor[0] receive the full amount that would be vetor[0]=10.

1 answer

6


Dear,

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.