I'm having trouble on the last part of my program. The code substracts an array p[j]
with an input number nStevilo
and then puts in into absolute. It then compares the result with a substraction of an array p[j++]
. The code should go through the array and find the smallest value and append it into najblizjeStevilo
, but for some reason it doesn't work?
while (j < 20){
if (abs(p[j] - nStevilo) < abs(p[j++] - nStevilo)){
najblizjeStevilo = p[j];
}
}
The array includes 20 prime numbers, starting from 2 (2, 3, 5, 7, 11...), so p[0]
= 2, p[1]
= 3...
Aucun commentaire:
Enregistrer un commentaire