4
use module 10; Example:
7 4 8 9 3 1 0 7 2 <== Dados
x x x x x x x x x
2 1 2 1 2 1 2 1 2 <== Peso
= = = = = = = = =
14 4 16 9 6 1 0 7 4 <= Resultado
1+4=5 1+6=7
//resultado da multiplicação, cujo valor for maior que 10 (dez), os dígitos do resultado devem ser
//somados, resultando um valor menor que 10 (dez);
5 4 7 9 6 1 0 7 4 = 43 <== Resultado Final
//Somatório do resultado das multiplicações = 43
So far so good. Now comes my problem. How to find Multiple of 10 greater or equal to the sum of 43?
My current code:
for (int i = 0; i <= soma; i += 10) {
if ((i % 10) == 0) {
if (i >= soma) {
Multiplo = i;
}
}
}
I do not understand what is the expected result.
– Maniero
The figure you expect to find is 50 ? I didn’t quite understand what you asked.
– emanuelsn
That’s right, I need to find, 50 see my Cód. for (int i = 0; i <= sum; i += 10) { if ((i % 10) == 0) { if (i >= sum) { Multiple = i; } } }
– Fabrício Mendes
@Manufacturers Monealanamendes Whenever you have a pole code to help people understand the problem and how far you’ve come.
– Maniero
It is not necessary to check whether
i mod 10
is equal to 0, because you always increment the variable with 10.– Luis Henrique