Jump to content
wikedx

problema afisare cate numere prime are vectorul

Recommended Posts

Salut am o problema cu afisarea numerelor prime din vectorul

<?php
error_reporting(E_ALL ^ E_NOTICE);
$ok=0;
$k=0;
$d=2;
$i=1;
$vectorS = array(31,33,434,2);
for( $i; $i <= 4; $i++ )
{
$ok=1;
for( $d; $d <= $vectorS[i]/2; $d++ )
{
if($vectorS[i]%$d==0)
$ok=0;
if($ok==1)
$k++;
}
}
if($k>0)
print $k;
else
print 'Nu exista';
?>

Imi afiseaza "Nu exista" in loc de "2"

Executare cod online: http://bit.ly/11UMqnf

Apasati pe butonul Execute Code

Edited by wikedx
Link to comment
Share on other sites

Salut am o problema cu afisarea numerelor prime din vectorul

<?php
error_reporting(E_ALL ^ E_NOTICE);
$ok=0;
$k=0;
$d=2;
$i=1;
$vectorS = array(31,33,434,2);
for( $i; $i <= 4; $i++ )
{
$ok=1;
for( $d; $d <= $vectorS[$i]/2; $d++ )
{
if($vectorS[$i]%$d==0)
$ok=0;
if($ok==1)
$k++;
}
}
if($k>0)
print $k;
else
print 'Nu exista';
?>

Imi afiseaza "Nu exista" in loc de "2"

Executare cod online: PHP Sandbox, test PHP online, PHP tester

Apasati pe butonul Execute Code


<?php
error_reporting(E_ALL ^ E_NOTICE);
$ok=0;
$k=0;
$d=2;
$i=1;
$vectorS = array(31,33,434,2);
for($i = 0; $i < 4; $i++ )
{
$ok=1;
for( $d = 2; $d <= $vectorS[i]/2; $d++ )
{
if($vectorS[i]%$d==0)
$ok=0;
}
if($ok==1)
$k++;
}
if($k>0)
print $k;
else
print 'Nu exista';
?>

Edited by Ganav
Link to comment
Share on other sites

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.   Paste as plain text instead

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