Answer the question
In order to leave comments, you need to log in
What needs to be done in the assignment?
There is a program for creating a table of prime numbers.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
int p,d,cases;
for (p=1; p<=100; ++p) {
cases = 1;
for (d = 2; d<p; ++d)
if (p % d == 0)
cases = 0;
if (cases != 0)
NSLog(@"%i",p);
}
}
return 0;
}
for (d = 2; d<p || cases == 1; ++d)
(p % 2 == 0 || p % 5 == 0)
like I did it right?
Answer the question
In order to leave comments, you need to log in
Why add Cases to the condition? After all, Cases is roughly zero value 1-True, 0-False.It is then to add - to interrupt the execution of the loop when the value has already been found.
Loop until Cases is 1?It says add to for, not replace , so that's not the only condition.
The program turns out to be in cycles or I am mistaken?You are wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question