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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.