|
-Laboratoriya. Switch tanlash operatoriga doir dastur tuzish
|
bet | 126/154 | Sana | 08.01.2024 | Hajmi | 5,29 Mb. | | #131939 |
Bog'liq Majmua9-Laboratoriya. Switch tanlash operatoriga doir dastur tuzish.
Misol.1. Agar x>y sharti to’g’ri bajarilsa x y dan katta degan natija chiqsin aks holda x y dan kichik degan natijani C# tilida ?: operatori yordamida chiqsin.
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 x = 20, y = 10;
var result = x > y ? "x y dan katta" : "x y dan kichik";
Console.WriteLine(result);
Console.ReadKey();
}
}
}
1-misolni if-else bloki yordamida quyidagicha bajaramiz:
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 x = 10, y = 100;
if (x > y)
Console.WriteLine("x y dan katta");
else
Console.WriteLine("x y dan kichik");
}
}
}
1-misolda sonlarni teng bo’lish shartini ham qo’shamiz
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 x = 10, y = 100;
string result = x > y ? "x y dan katta" :
x < y ? "x y dan kichik" :
x == y ? "x y teng" : "Natija topilmadi";
Console.WriteLine(result);
Console.ReadLine();
}
}
}
Misol.2. Quyidagi natijani hisoblang:
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)
{
double a, x, y;
a = double.Parse(Console.ReadLine());
x = double.Parse(Console.ReadLine());
y = x < 1.3 ? Math.PI * x * x - 7.0 / (x * x) : x == 1.3 ? a * Math.Pow(x, 3) + 7 * Math.Sqrt(x) : Math.Tan(x + 7 * Math.Sqrt(x));
Console.WriteLine(y);
Console.ReadLine();
}
}
}
|
| |