0
Cant write algorithm, prime numbers
1.Define int a(number)= 101 2.Define int b(divisor)= 2 3.if b is lower then a? yes-go to step 5 no - go to step 4 4. print : "b+ b +is prime number " and end the program 5. if a%b==0 yes- go to step 6 no-go to step 7 6. print: " a +a +is not prime number, u can divide by b" end the program 7.increase b by +1 and go to step 3
4 Réponses
0
your algorithm is pretty much ok , you only need to define b as numbers below integer value of a under radical
better explanation: you must find value of a under radical and put it in b.
than you must define a loop that will run b times
than each time do a%b and check if it is 0
if the loop finished without any successful value , than the number is not prime
good luck
0
Hi could you explain me one thing?
i ve done my code but i dont keep the order as my teacher wrote.. can i code his algorithm this way ? IT works but i start From number 5th. not. 1st but also go through his 1st later.
Is someone able to write that(his) algorithm in order? or i dont have to keep order and with my code is allright? thanks :)
int a = 8;
int b=2;
if(a%b==0){
sys.out.println("not prime");
}
else{
for(int i=b;i<b;i++){
if(a<b &&a%b==0){
sys.out.println("not prime");
}
else{
sys.out.println("prime number");
}}}
0
i think you have problems in your loop conditions (or i don't understand its purpose ?) why is i set to b and then you check if it is smaller ?
0
Do how would you write this algorithm? I m not sire if my solution is correct, but IT works