Jump to content

php c


strpth

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.