linkedin facebook linkedin facebook nod32

PHP da mаntiqiy оperаtоrlаr va uning tadbiqi

Muallif: Mengliyev Shaydulla abdusalomovich

Qo`shilgan sana: 2020-04-06

PHP da mаntiqiy оperаtоrlаr va uning tadbiqi

Razryadli mantiqiy amallar. Dastur tuzish tajribasi shuni ko‘rsatadiki, odatda qo‘yilgan masalani yechishda biror holat ro‘y berganligini yoki yo‘qligini ifodalash uchun 0 va 1 qiymat qabul qiluvchi bayroqlardan foydalaniladi. Shu maqsadda bir yoki undan ortiq baytli o‘zgaruvchilardan foydalanish mumkin. Masalan, bool (mantiqiy) tupdagi o‘zgaruvchini shu maqsadda ishlatsa bo‘ladi. Boshqa tomondan, bayroq sifatida baytning razryadlaridan foydalanish ham mumkin. Chunki razryadlar faqat ikkita qiymatni – 0 va 1 sonlarini qabul qiladi. Bir baytda 8 razryad bo‘lgani uchun unda 8 ta bayroqni kodlash imkoniyati mavjud. Quyidagi jadvalda PHP tilida bayt razryadlari ustida mantiqiy amallar majmuasi keltirilgan.
Bayt razryadlari ustida mantiqiy amallar

Amallar

Or yoki & - Mantiqiy VA (ko’paytirish)
Xor yoki | - Mantiqiy yoki (qo’shish))
And yoki ^ - Istisno qiluvchi YOKI
!-Mantiqiy INKOR (inversiya)

Razryadli mantiqiy amallarning bajarish natijalarini jadval ko‘rinishida ko‘rsatish mumkin.
Razryadli mantiqiy amallarni bajarish natijalari


А

В

А&В

А|В

А^В

0

0

0

0

0

0

1

0

1

1

1

0

0

1

1

1

1

1

1

0

<?php
$a = $_POST['a'];
$b = $_POST['b'];
echo($a&$b);
echo"<br>";
echo(($a|$b));
echo"<br>";
echo($a^$b);
?>
<form action="misol.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

А

!А

0

1

1

0

 

<?php
$a = $_POST['a'];
$b = $_POST['b'];
echo(!$a);
echo"<br>";
echo(!$b);
?>
<form action="inkor.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

Yuqoridagi keltirilgan misol uchun qo‘riqlash tizimini ifodalovchi bir baytli char tupidagi o‘zgaruvchini e’lon qilish mumkin.
Bu guruh оperаtоrlаri rаzryadli оperаtоrlаrdаn fаrqli mаntiqiy (boolean) o‘zgаruvchilаr bilаn ishlаydi vа bоshqаruvchi kоnstruktsiyalаr:sikllаr vа shаrtlаrdа ishlаtilаdi. Mаntiqiy o‘zgаruvchilаr yoki to‘g‘rirоg‘i Boolean tipidаgi o‘zgаruvchilаr fаqаt ikki qiymаtgа egаlаr: true(rоst)false(yolg‘оn). Ifоdаlаrdа truefalse qiymаtlаrini 1(0 dаn fаrqli iхtiyoriy sоn) vа 0 gа аlmаshtirish mumkin. Bu imkоniyat mахsus true i false qiymаtlаrigа egа bo‘lmаgаn php tilining merоsidir.

1-masala. A butun soni berilgan. Jumlani rostlikka tekshiring: “A soni toq son”.

<?php
$a = $_POST['a'];
var_dump($a%2==1);
?>
<form action="1-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

2-masala. Ikkita butun A va В sonlari berilgan. Jumlani rostlikka tekshiring: “A>2 va B<=3”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
var_dump(($a>2)and($b<=3));
?>
<form action="2-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

3-masala Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka tekshiring: “A<=В<=С”

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump(($a<=$b)and($b<=$c));
?>
<form action="3-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

4-masala. Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka tekshiring: “B soni A va С sonlari orasida yotadi”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump(($a<=$b)and($b<=$c));
?>
<form action="3-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

5-masala. Ikkita butun A va В sonlari berilgan. Jumlani rostlikka tekshiring: “A va В sonlari toq sonlar”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
var_dump(($a%2==1)and($b%2==1));
?>
<form action="5-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

6-masala Ikkita butun A va В sonlari berilgan. Jumlani rostlikka tekshiring: “A va В sonlarning faqat bittasi toq son”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
var_dump(($a%2==1)or($b%2==1));
?>
<form action="6-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

7-masala Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka tekshiring: “А, В, С sonlarning har biri musbat”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump(($a>0)and($b>0)and($c>0));
?>
<form action="7-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

8-masala Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka tekshiring: “А, В, С sonlaridan faqat bittasi musbat son”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump((($a>0)and($b<0)and($c<0))or(($a<0)and($b>0)and($c<0))or (($a<0)and($b<0)and($c>0)));
?>
<form action="8-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

9-masala. Musbat butun son berilgan. Jumlani rostlikka tekshiring: “Berilgan son ikki xonali juft son”.

<?php
$a = $_POST['a'];
var_dump(($a>9)and($a<100)and($a%2==0));
?>
<form action="9-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

10-masala. Musbat butun son berilgan. Jumlani rostlikka tekshiring: “Berilgan son uch xonali toq”.

<?php
$a = $_POST['a'];
var_dump((($a>99)and($a<1000)and($a%2==1)));
?>
<form action="10-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

11-masala. Jumlani rostlikka tekshiring: “Berilgan uchta butun sonlarning hech bo‘lmaganda 2 tasi bir biriga teng”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump(($a=$b)or($a=$c)or($b=$c));
?>
<form action="11-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

12-masala. Uch xonali son berilgan. Jumlani rostlikka tekshiring: “Ushbu sonning barcha raqamlari xar xil”.

<?php
$a = $_POST['a'];
$x=floor($a/100);
$y=floor($a/10)% 10;
$z=floor($a/10);
var_dump(($x<>$y)and($x<>$z)and($y<>$z));
?>
<form action="12-masala.php" method="post">
<p>Uch xonali sonni kiriting <input name="a" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

13-masala. А, В, С sonlar beilgan (A soni noldan farqli). D=B2-4AC diskerminantdan foydalanib, jumlani rostlikka tekshiring: “Ax2+Bx+C=0 kvadrat tenglama haqiqiy ildizga ega”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$d=pow($b,2)-4*$a*$c;
var_dump(($a<>0)and($d>=0));
?>
<form action="13-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

14-masala. x, у sonlar berilgan. Jumlani rostlikka tekshiring: “Koordinatalari (x,y) bo‘lgan nuqta, koordinata choragining ikkinchisida yotadi”.

<?php
$x = $_POST['x'];
$y = $_POST['y'];
var_dump(($x<0)and($y>0));
?>
<form action="14-masala.php" method="post">
<p>x= <input name="x" type="text"></p>
<p>y= <input name="y" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

15-masala. (x, y), (x1, y1), (x2, y2) sonlari berilgan. Jumlani rostlikka tekshiring: “Koordinatalari (x,y) bo‘lgan nuqta, chap yuqori cho’qqisi (x1,y1) koordinatalarga ega bo‘lgan va o‘ng pastikisi (x2,y2) bo‘lgan, tomonlari esa koordinata o‘qlariga parallel bo’lgan to‘rtburchak ichida yotadi”.

<?php
$x = $_POST['x'];
$y = $_POST['y'];
$x1 = $_POST['x1'];
$y1 = $_POST['y1'];
$x2 = $_POST['x2'];
$y2 = $_POST['y2'];
var_dump(($x>$x1)and($x2>$x))and(($y1>$y)and($y>$y2));
?>
<form action="15-masala.php" method="post">
<p>x= <input name="x" type="text"></p>
<p>y= <input name="y" type="text"></p>
<p>x1= <input name="x1" type="text"></p>
<p>y1= <input name="y1" type="text"></p>
<p>x2= <input name="x2" type="text"></p>
<p>y2= <input name="y2" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

16-masala. a, b, с butun sonlari berilgan. Jumlani rostlikka tekshiring: “a, b, c tomonli uchburchak teng tomonli bo‘ladi”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump(($a=$b)and($a=$c)and($b=$c));
?>
<form action="16-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

17-masala. a, b, с butun sonlar berilgan. Jumlani rostlikka tekshiring: “a, b, с tomonli uchburchak yasash mumkin”.

<?php
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
var_dump((($a+$b)>$c)or (($a+$c)>$b)or (($c+$b)>$a));
?>
<form action="17-masala.php" method="post">
<p>a= <input name="a" type="text"></p>
<p>b= <input name="b" type="text"></p>
<p>c= <input name="c" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

18-masala. Shaxmat doskasining x, у koordinatalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Doskaning chap pastki maydoni (1,1) qoraligini hisobga olib, jumlani rostlikka tekshiring: “Berilgan (x, y) maydon oq”.

<?php
$x = $_POST['x'];
$y = $_POST['y'];
var_dump((($x+$y)%2==1));
?>
<form action="18-masala.php" method="post">
<p>x= <input name="x" type="text"></p>
<p>y= <input name="y" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

19-masala. Shaxmat doskasining ikkita turli (x1, y1), (x2, y2) koordinalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Jumlani rostlikka tekshiring: “Ruh bir yurishda bir maydondan ikkinchisiga o‘ta oladi”.

<?php
$x1 = $_POST['x1'];
$y1 = $_POST['y1'];
$x2 = $_POST['x2'];
$y2 = $_POST['y2'];
var_dump(($x1=$x2)or($y1=$y2));
?>
<form action="19-masala.php" method="post">
<p>x1= <input name="x1" type="text"></p>
<p>y1= <input name="y1" type="text"></p>
<p>x2= <input name="x2" type="text"></p>
<p>y2= <input name="y2" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

20-masala. Shaxmat doskasining ikkita turli (x1, y1), (x2, y2) koordinalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Jumlani rostlikka tekshiring: “Ot bir yurishda bir maydondan ikkinchisiga o‘ta oladi”.

<?php
$x1 = $_POST['x1'];
$y1 = $_POST['y1'];
$x2 = $_POST['x2'];
$y2 = $_POST['y2'];
var_dump((abs($y2-$y1)==2)or(abs($x2-$x1)==2)and(abs($y2-$y1)==1));
?>
<form action="20-masala.php" method="post">
<p>x1= <input name="x1" type="text"></p>
<p>y1= <input name="y1" type="text"></p>
<p>x2= <input name="x2" type="text"></p>
<p>y2= <input name="y2" type="text"></p>
<p><input type="submit" value="Hisoblash"></p>
</form>

MUSTAQIL BAJARISH UCHUN TOPSHIRIQLAR

1-masala. A butun soni berilgan. Jumlani rostlikka tekshiring: “A soni musbat”.
2-masala. A butun soni berilgan. Jumlani rostlikka tekshiring: “A soni juft son”.
3-masala. Ikkita butun A va В sonlari berilgan. Jumlani rostlikka tekshiring: “A>=0 yoki В<-2”
4-masala. Ikkita butun A va В sonlari berilgan. Jumlani rostlikka tekshiring: “A va В sonlarning hech bo‘lmaganda bittasi toq son”.
5-masala. Ikkita butun A va В sonlari berilgan. Jumlani rostlikka tekshiring: “A va В sonlarining har ikkalasi ham yoki toq son yoki juft son”.
6-masala. Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka tekshiring: “А, В, С sonlarning hech bo‘lmaganda bittasi musbat”.
7-masala. Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka tekshiring: “А, В, С sonlardan faqat ikkitasi musbat son”.
8-masala. Jumlani rostlikka tekshiring: “Berilgan uchta butun sonlarning hech bo‘lmaganda bir jufti o‘zaro qarama-qarshi”.
9-masala. Uch xonali son berilgan. Jumlani rostlikka tekshiring: “Ushbu sonning raqamlari ketama - ket o‘suvchi bo‘lib joylashgan”.
10-masala. Uch xonali son berilgan. Jumlani rostlikka tekshiring: “Ushbu sonning raqamlari ketama - ket o‘suvchi bo’lib joylashgan yoki kamayuvchi ketma - ketlikka ega”.
11-masala. Uch xonali son berilgan. Jumlani rostlikka tekshiring: “Ushbu sonni chapdan o‘qiganda ham, o‘ngdan o‘qiganda ham bir xil”.
12-masala. x, у sonlar berilgan. Jumlani rostlikka tekshiring: “Koordinatalri (x,y) bo‘lgan nuqta koordinata choragining to‘rtinchisida yotadi”.
13-masala. x, у sonlar berilgan. Jumlani rostlikka tekshiring: “Koordinatalri (x,y) bo‘lgan nuqta koordinata choragining ikkinchisida yoki uchunchisida yotadi”.
14-masala. x, у sonlar berilgan. Jumlani rostlikka tekshiring: “Koordinatalri (x,y) bo’lgan nuqta koordinata choragining birinchi yoki uchunchisida yotadi”.
15-masala. a, b, с butun sonlari berilgan. Jumlani rostlikka tekshiring: “a, b, c tomonli uchburchak teng yonli bo‘ladi”.
16-masala. a, b, с butun sonlar berilgan. Jumlani rostlikka tekshiring: “a, b, c tomonli uchburchak to‘g‘ri burchakli”.
17-masala. Shaxmat doskasining ikkita turli (x1, y1), (x2, y2) koordinalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Jumlani rostlikka tekshiring: “Berilgan maydonlar bir xil rangda”.
18-masala. Shaxmat doskasining ikkita turli (x1, y1), (x2, y2) koordinalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Jumlani rostlikka tekshiring: “Shoh bir yurishda bir maydondan ikkinchisiga o‘ta oladi”.
19-masala. Shaxmat doskasining ikkita turli (x1, y1), (x2, y2) koordinalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Jumlani rostlikka tekshiring: “Fil bir yurishda bir maydondan ikkinchisiga o‘ta oladi”.
20-masala. Shaxmat doskasining ikkita turli (x1, y1), (x2, y2) koordinalari berilgan (1-8 oraliqda yotuvchi butun sonlar). Jumlani rostlikka tekshiring: “Farzin bir yurishda bir maydondan ikkinchisiga o‘ta oladi”.

286 marta o`qildi.

Parol:
Eslab qolish.


Ro`yhatdan o`tish

testing

+998915878681

Siz o`z maxsulotingizni 3D reklama ko`rinishda bo`lishini xohlaysizmi? Unda xamkorlik qilamiz.

3D Reklama


Рейтинг@Mail.ru
Рейтинг@Mail.ru

Besucherzahler
счетчик посещений