Ma’ruza mashg`ulot uchun


Download 0.85 Mb.
bet20/49
Sana19.06.2023
Hajmi0.85 Mb.
#1600219
1   ...   16   17   18   19   20   21   22   23   ...   49
Bog'liq
1-semestr maruzalar

Listing 4.3-Ternar: Kiritilgan sonni 2 dan 5 gacha bo‘lgan sonlarga qoldiqsiz bo‘linish yoki bo‘linmasligini ko‘rsatuvchi dasturini.


2-Misol.Kiritilgan ikki sonni solishtirish uchun if..else va ternar operatorlaridan foydalanib dastur tuzing.

using System;
namespace kattasini_topish_consol
{
class Program
{
static void Main(string[] args)
{
l1:
Console.Write("Birinchi sonni kiriting: ");
int a = int.Parse(Console.ReadLine());
Console.Write("Ikkinchi sonni kiriting: ");
int b=int.Parse(Console.ReadLine());.


//Qisqa shart operatori bilan a va b larni teng emasligini tekshiramiz
Console.WriteLine(a!=b ?
a+" soni "+b+" soniga teng emas":
a+" soni "+b+" soniga teng");
//Agar a son b songa tengligi yolg‘on bo‘lsa,
if (!(a==b)) {
if(a>b) Console.WriteLine(a+" > "+b);
else Console.WriteLine(a+" < "+b);
}
//Bitta bo‘sh qator tashlash
Console.WriteLine();
//Kerakli tugmalar bosish haqida xabar chiqarish
Console.Write("\n Takrorlash uchun R ni bosing\n Dasturdan chiqish uchun X ni bosing;");
char x;
l0:
//x ga bosilgan tugma qiymatini o‘zlashtirish
x=Console.ReadKey().KeyChar;
if ((x == 'x') || (x == 'X'))
goto l2; // x tugma bosilsa l2 metkaga o‘tish
else if ((x == 'r') || (x == 'R'))
{
Console.Clear();
goto l1; //r tugma bosilsa l1 metkaga o‘tish
}


goto l0; //Boshqa tugmalar bosilsa l0 metkaga o‘tilsin.
l2:; // dastur oxiri, tugashi
}
}
}





Download 0.85 Mb.

Do'stlaringiz bilan baham:
1   ...   16   17   18   19   20   21   22   23   ...   49




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling