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; } ?> Link to comment https://forums.phpfreaks.com/topic/295997-php-c/ Share on other sites More sharing options...
ginerjm Posted May 1, 2015 Share Posted May 1, 2015 php d? Link to comment https://forums.phpfreaks.com/topic/295997-php-c/#findComment-1510503 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; } } Link to comment https://forums.phpfreaks.com/topic/295997-php-c/#findComment-1510507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.