A prime number program

Discussion in 'Scripts' started by goldenwaters, Feb 15, 2012.

to remove all ads.
  1. goldenwaters

    goldenwaters Member

    Messages:
    114
    Hello friends,
    please dont feel disappointed by my question. Im not too perfect in php.
    Im battling at writing a prime number program. I did it to this point: if the textbox is empty, it tells the user to input a number. When a number less than 2 is entered, it tells the user to input a higher value. Now my problem is, when i input a greater than 2 number like 4, it still tells me its a prime number. Please help me.
    Thanks,
    Golden Waters.
     
  2. DesignerBill

    DesignerBill New Member

    Messages:
    145
    Can't be of any help without the code...
     
  3. che09

    che09 New Member

    Messages:
    337
    This is right. You have to share the code so that we can respond rightly!
     
  4. goldenwaters

    goldenwaters Member

    Messages:
    114
    Ok DesignerBill. Here it is:
    <?php
    //collects the number entered by user.
    $num = $_POST['num'];
    if(empty($num)){
    die("ERROR: Please enter a number.");
    }
    if($num<2){
    echo "This is no prime number.";
    }elseif($num %= 1 && ...){\\i have problems here completing this code.
    echo "This is a prime number";
    }else{
    echo "This is NOT a prime number";
    }

    ?>
     
  5. Phreaddee

    Phreaddee Super Moderator Staff Member

    Messages:
    1,978
  6. goldenwaters

    goldenwaters Member

    Messages:
    114
    I will check it out phreaddee. Thanks man.
     

Share This Page