strpth Posted May 1, 2015 Share Posted May 1, 2015 Im new to php and trying to write a program that checks if a given number is prime but does not belong to the fibonaci series. The program should return 1 if the numer is prime and does not belong to the fibonaic series or 0 But each time i got OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO here is the code please reply ASAP <?php $a=0; $b=1; $i; $count=0; $num=10; while(num) { $k = $a+$b; $a = $b; $b = $k; $count++; while(k) { if(k%i==0) echo 0; } if(k==i) echo 1; } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 1, 2015 Share Posted May 1, 2015 php d? Quote Link to comment Share on other sites More sharing options...
maxxd Posted May 1, 2015 Share Posted May 1, 2015 You're not using variable in your while() loop at all. Also, you don't assign a value to $i, which should produce a division by zero error on every iteration of the loop. It's way too early for me to do math, but figure out what value to assign to $i, and make k and i variables in your while loop like so: while($k){ if($k%$i == 0){ echo 0; } if($k == $i){ echo 1; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.