DUDA EN C++

05/08/2004 - 20:24 por Pedro Pablo T. | Informe spam
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++

Preguntas similare

Leer las respuestas

#1 Hernán
05/08/2004 - 20:58 | Informe spam
"Pedro Pablo T." escribía:

[...]
Mostrar la cita
porque (0 == 0) vale 1

Hernán (28)
Quilmes (ar)
"Tristeza não tem fim, felicidade sim."
#2 Anonimo
09/08/2004 - 14:56 | Informe spam
Mostrar la cita
C++, ya que estoy
Mostrar la cita
required
Mostrar la cita
defined
Mostrar la cita
is found
Mostrar la cita
exact division
Mostrar la cita
division
Mostrar la cita
no remainder from
Mostrar la cita
(primes+i) (remember that
Mostrar la cita
statement causes
Mostrar la cita
since the candidate
Mostrar la cita
found si la división
Mostrar la cita
de un principiante
Mostrar la cita
VERDADERO O FALSO EN C++ 1 O 0
Mostrar la cita
Ads by Google
Search Busqueda sugerida