Stopp Posted August 8, 2006 Report Share Posted August 8, 2006 (edited) kā var pārbaidīt, vai dotais mainīgais ir pāra skaitlis ? mēģināju šitā if (eregi(".", ($v/2))) { // nav pāra skaitlis } else { // ir } bet kaut kas īsti nestrādā, visu laiku saka, ka nav pāra skaitlis. kas par vainu un kā labāk pārbaudīt ? paldies. Edited August 8, 2006 by Stopp Link to comment Share on other sites More sharing options...
Paulinjsh Posted August 8, 2006 Report Share Posted August 8, 2006 (edited) $v = explode( '.', $v ); if( $v[0]%2 == 0 ) { echo 'ir'; } else { echo 'nav'; } Edited August 8, 2006 by Paulinjsh Link to comment Share on other sites More sharing options...
Stopp Posted August 8, 2006 Author Report Share Posted August 8, 2006 paldies, itkā strādā :P Link to comment Share on other sites More sharing options...
Paulinjsh Posted August 8, 2006 Report Share Posted August 8, 2006 Par ātrumu gan nezinu un nezinu ko tev tur īsti vajaga. Tad ir jātestē :) Link to comment Share on other sites More sharing options...
Delfins Posted August 8, 2006 Report Share Posted August 8, 2006 kāds vēl explode? vispirms pārbaudam vai is_int() un tad vai dalās ar 2 (kaut vai pēdējais cipars) Link to comment Share on other sites More sharing options...
lame Posted August 8, 2006 Report Share Posted August 8, 2006 http://lv.php.net/manual/en/function.bcmod.php vai arī <?php function bc_is_even($int_str) { if (0 < strlen($int_str)) { return !((substr($int_str, -1)) % 2); } else { // error return 0; } } ?> Link to comment Share on other sites More sharing options...
goldy Posted August 8, 2006 Report Share Posted August 8, 2006 is_int() neko nedos, tik un tā lielākā daļa mainīgo iekš PHP stringi, vajag: fmod($x, 2); ja 0 tad pāra, ja nav tad nepāra un visa gudrība. Link to comment Share on other sites More sharing options...
Stopp Posted August 8, 2006 Author Report Share Posted August 8, 2006 kāds vēl explode?vispirms pārbaudam vai is_int() un tad vai dalās ar 2 (kaut vai pēdējais cipars) to jau es mēģināju sākumā (pārbaudot, vai dalījums satur komatu, t.i. vai ir, vai nav vesels skaitlis), bet kaut kas nestrādāja.. Link to comment Share on other sites More sharing options...
Paulinjsh Posted August 8, 2006 Report Share Posted August 8, 2006 ok, kļūda man, nesapratu jautājumu :D Domāju šamam vajaga nočekot vai skaitļa veselā daļa ir pāra skaitlis :) Link to comment Share on other sites More sharing options...
Stopp Posted August 8, 2006 Author Report Share Posted August 8, 2006 nekas, Paulinj, strādā tāpat :) Link to comment Share on other sites More sharing options...
bubu Posted August 8, 2006 Report Share Posted August 8, 2006 kā var pārbaidīt, vai dotais mainīgais ir pāra skaitlis ? Baidies, pāra skaitli! Link to comment Share on other sites More sharing options...
Toms Posted August 11, 2006 Report Share Posted August 11, 2006 if ($x % 2 == 0){ // paara skaitlis } Link to comment Share on other sites More sharing options...
Recommended Posts