static void Main(string[] args) { int i, num, factor; bool isprime; for (num = 2; num < 10; num ++) { isprime = true; factor = 0; for (i=2; i <= num/2; i++) { if ((num % i) == 0) { isprime = false; factor = i; } } if (isprime) Console.WriteLine(num + " - простое число"); else Console.WriteLine("Наибольший множитель числа " + num + " равен " + factor); } Console.ReadLine(); I must say that the code is working. The program receives the number num , divides it by i , according to the condition and displays that the number is num :
- Prime number
- The largest factor of
numisi
Now the question is: why is the value of isprime first taken to be true , then false and in the if takes true , although (if you take the number 2) it turns out that the last if includes isprime=false ? I'm confused.