|
-Laboratoriya. if-else, ?: shart operatorlariga doir dastur tuzish
|
bet | 124/154 | Sana | 08.01.2024 | Hajmi | 5,29 Mb. | | #131939 |
Bog'liq Majmua8-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();
}
}
}
|
| |