C# Operatorlar (Amallar)



Yüklə 0,64 Mb.
Pdf görüntüsü
səhifə8/8
tarix28.11.2023
ölçüsü0,64 Mb.
#138148
1   2   3   4   5   6   7   8
C# tili

 
2 0 , 1 0
Bir o’zgaruvchi qiymatini bir necha shartlar orqali tekshirish uchun 
ichma-ich bir necha shart operatorlaridan foydalanish mumkin:
int
temp

25

if
(
temp

21


if
(
temp

26


Console.WriteLine("Temperatura meyorda"); 
if
(
temp
== 
24


Console.WriteLine("ishlash sharoiti optimal"); 

else

Console .WriteLine ("ishlash sharoiti optimal emas\n" + "optimal temperatura 24");



Console.ReadKey(); 
Ko’p shartlilik qo’llanilishi. Bunda bir necha shartni bir vaqtda 
tekshirish zarurati hisobga olinadi. C# tilida buning uchun maxsus 
qo’shish (shartni) kalit so’zlari mavjud : && - va, | | - yoki, ! – inkor (!= 
bo’lsa, teng emas ma’nosida). Masalan: 
int
n1 = 
5

int
n2 = 
0

if
( (n1
== 
5
)
&& 
(n2
== 
5
)) 
Console.
WriteLine(
"Salom"
)

else
Console.
WriteLine(
"Yoshlar"
)

if
((n1
== 
5
)
|| 
(n2
== 
5
)) 


Console.
WriteLine(
"Buxoro"
)

else
Console.
WriteLine(
"Vaqt"
)

Console.
ReadKey()

Bu misolda har bir if operatori ikkita shartni tekshirib boradi.
Agar tekshirilayotgan shart nisbatan sodda bo’lsa, shart amali ni “?: 
” ko’rinishini ishlatish mumkin. Bu operator quyidagi ko’rinishga ega:
:;
if shart operatoriga o’xshash holda bus hart amali quyidagicha 
ishlaydi: agar  rost(true) bo’lsa  bajariladi, aks 
holda oda2>. Odatda ifodalar qiymatlari birorta o’zgaruvchiga 
o’zlashtiriladi. 
Misol: 2 ta sondan kattasini tuzuvchi programma tuzilsin.
int
a,b; 
a=
int
.
Parse
(
Console
.
ReadLine
()); 
b=
int
.
Parse
(
Console
.
ReadLine
()); 
int
max = (a>b) ? a : b; 
Console
.
WriteLine
(max); 
Console
.
ReadKey
(); 
Masalan: 
Haqiqiy turga tegishli 

o‘zgaruvchi berilgan. Uning qiymatiga mos 
keluvchi 

funksiyaning qiymati topilsin. 
f: 
Console
.
Write
(
"x="
);
double
x=
double
.
Parse
(
Console
.
ReadLine
());
if
(x>
0
)
{
if
(
0
2
)
Console
.
WriteLine
(
"f(x)="
+Math.
Pow
(x,
2
));
else
Console
.
WriteLine
(
"f(x)="

4
);
}
else
Console
.
WriteLine
(
"f(x)="
+ -x);
goto
f;
Console
.
ReadKey
(); 



Yüklə 0,64 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə