-Laboratoriya. if-else, ?: shart operatorlariga doir dastur tuzish




Download 5,29 Mb.
bet124/154
Sana08.01.2024
Hajmi5,29 Mb.
#131939
1   ...   120   121   122   123   124   125   126   127   ...   154
Bog'liq
Majmua

8-Laboratoriya. if-else, ?: shart operatorlariga doir dastur tuzish.

1-M. Sonni juft yoki toqligini tekshirish


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EKUB


{
class Program
{
static void Main(string[] args)
{
int a;
Console.WriteLine("Raqam kiriting:");
a = Convert.ToInt32(Console.ReadLine()); // sonni klaviyaturadan kiritish
if (a % 2 == 0) //sonni 2 ga qoldiqli bo'linishini tekshirish
{
Console.WriteLine("Son " + a + " - juft");
}
else
{
Console.WriteLine("b " + a + " - toq");
}
Console.ReadKey();
}
}
}
2-M. Ikkita sonni qaysi kattaligini tekshirish.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EKUB


{
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Birinchi sonni kiriting:");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ikkinchi sonni kiriting:");
b = Convert.ToInt32(Console.ReadLine());
if (a > b)
Console.WriteLine("Birinchi son ikkinchi sondan katta");
else if (a < b)
Console.WriteLine("ikkinchi son birinchi sondan katta");
else
Console.WriteLine("Sonlar teng");

Console.ReadKey();


}
}
}
3-m. Haroratni tekshirish
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EKUB


{
class Program
{
static void Main(string[] args)
{
int t;
Console.WriteLine("Haroratni kiriting");
t = Convert.ToInt32(Console.ReadLine());
if (t < -20 || t > 40) //agar harorat -20 dan kichik va 40 dan katta bo'lsa
Console.WriteLine("Uyda o'tirish mumkin");
else
Console.WriteLine("Tashqariga chiqishingiz mumkin");
Console.ReadKey();
}
}
}
4-m. Taqqoslash
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EKUB


{
class Program
{
static void Main(string[] args)
{
int n5 = 13;
int n6 = 12;
if (n5 < n6)
{
Console.WriteLine("Ikkinchi sondan birinchi son kichik");
}
else if (n5 > n6)
{
Console.WriteLine("Birinchi son katta");
}
else
{
Console.WriteLine("Sonlar teng");
}
Console.ReadLine();
}
}
}

Download 5,29 Mb.
1   ...   120   121   122   123   124   125   126   127   ...   154




Download 5,29 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



-Laboratoriya. if-else, ?: shart operatorlariga doir dastur tuzish

Download 5,29 Mb.