Hola a todos tengo una duda existencial en un código en C++, ya que estoy
empezando a estudiar
C++
un extracto del código lo copio abajo
**********************
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int MAX = 100; // Number of primes required
long primes[MAX] = { 2,3,5 }; // First three primes defined
long trial = 5; // Candidate prime
int count = 3; // Count of primes found
int found = 0; // Indicates when a prime is found
for(int i = 0; i < count; i++)
{
found = (trial % *(primes+i)) == 0; // True for exact division
}
}
**************************
mi duda esta en la linea:
found = (trial % *(primes+i)) == 0; // True for exact division
la explicación del libro es:
This statement sets the variable found to be 1 if there's no remainder from
dividing the value in trial by the current prime, *(primes+i) (remember that
this is equivalent to primes[i]), and 0 otherwise. The if statement causes
the for loop to be terminated if found has the value 1, since the candidate
in trial can't be a prime in that case.
Lo que no entiendo es porque le asigna 1 a la variable found si la división
es exacta .
No se si alguien generoso me lo podría explicar a nivel de un principiante
en C++
Leer las respuestas