Mavzu; Operatsion tizimlar haqida umumiy maʼlumot


public static double Sqrt(double d)


Download 0.91 Mb.
bet29/49
Sana18.10.2023
Hajmi0.91 Mb.
#1708956
1   ...   25   26   27   28   29   30   31   32   ...   49
Bog'liq
1-kurs Amaliyot Norboyev Sundor I

public static double Sqrt(double d) - d ning kvadrat ildizini qaytaradi.
public static double Tan(double a) - a ning tangensini qaytaradi.
public static double Tanh(double value) – value ning giperbolik tangensini qaytaradi.
public static double Truncate(double d) - d ning butun son qismini qaytaradi.
public static decimal Truncate(decimal d) - d ning butun son qismini qaytaradi.

Masalan:
x kg shokolad a so’m, y kg iris b so‘m tursa. 1 kg shokolad va 1 kg iris qancha turishi va ular narxidagi farq hisoblansin.
double x, y, a, b,m,n,p;
Console.Write("x=");
x = double.Parse(Console.ReadLine());
Console.Write("y=");
y = double.Parse(Console.ReadLine());
Console.Write("a=");
a = double.Parse(Console.ReadLine());
Console.Write("b=");
b = double.Parse(Console.ReadLine());
m = a/x;
n = b/y;
p=Math.Abs(m-n) ;
Console.WriteLine("1kg shokolad=" + a / x);
Console.WriteLine("1kg iris=" + b / y);
Console.WriteLine("Narxidagi farq =" +p);
Console.ReadKey();



float x,y;
Console.Write("x=");
x=float.Parse(Console.ReadLine());
Console.Write("y=");
y=float.Parse(Console.ReadLine());
Console.WriteLine((Math.Abs(x)-Math.Abs(y))/(1+Math.Abs(x*y)));
Console.ReadKey();



double a,b,c,p;
Console.Write("a=");
a=double.Parse(Console.ReadLine());
Console.Write("b=");
b=double.Parse(Console.ReadLine());
c=Math.Sqrt((a*a)+(b*b));
p=a+b+c;
Console.WriteLine("c="+(c)+" p="+(p));
Console.ReadKey();


double a,b,c,p;
Console.Write("a=");
a=double.Parse(Console.ReadLine());
Console.Write("b=");
b=double.Parse(Console.ReadLine());
Console.Write("c=");
c=double.Parse(Console.ReadLine());
p=a;
a=c;
c=b;
b=p;
Console.WriteLine("a="+(a)+" b="+(b)+" c="+(c));
Console.ReadKey();


double x,y;
Console.Write("x=");
x=double.Parse(Console.ReadLine());
y=4*Math.Pow((x-3),6)-7*Math.Pow((x-3),3)+2;
Console.WriteLine("y="+(y));
Console.ReadKey();


double a,b,c,p,s;
Console.Write("a=");
a=double.Parse(Console.ReadLine());
Console.Write("b=");
b=double.Parse(Console.ReadLine());
Console.Write("c=");
c=double.Parse(Console.ReadLine());
p=(a+b+c)/2;
s=Math.Sqrt(p*(p-a)*(p-b)*(p-c));
Console.WriteLine("s="+(Math.Round(s,2)));
Console.ReadKey();



Shart operatorlari. if, if-else, ?:



Reja:

1. if(shart) operatorlar;
2. ? :;
3.Masalalar yechish


Shart operatori boshqarishni qaysi tarmoqqa uzatishni ta’minlaydi. Shart operatorlaridan biri bu if shart operatoridir. if shart operatorining 3 xil ko’rininshi bo’lib, eng soda ko’rinishi quyidagicha:
if(shart) operatorlar;
Shart operatorining natijasi bool tipiga tegishli bo’lib, true(rost) yoki false(yolg’on) bo’lishi mumkin. C# da quyidagi munosabat amallari mavjud:
== - tenglik;
> - katta;
< - kichik;
>= - katta yoki teng;
<= - kichik yoki teng;
!= - teng emas.
if shart operatorining ikkinchi bir ko’rinishi if-else bo’lib, u quyidagicha yoziladi:
if(shart) operatorlar1;
else operatorlar2;
Agar shart rost bo’lsa, operator1 bajariladi, agar yolg’on bo’lsa, operator2 bajariladi. Agarda operator1 yoki operator2 dan so’ng bajarilishi lozim bo’lgan amallar soni 1 tadan ortiq bo’lsa ular figurali {} qavslar orasida yozilishi lozim. Masalan: a va b sonlarni kattasini a ga kichigini b ga yozish dasturi
int a, b, c;
a = 10; 
b=20;
if (a Console.WriteLine(a+" , "+b);
Console.ReadKey();
20 , 10
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 amalini “?: ” ko’rinishini ishlatish mumkin. Bu operator quyidagi ko’rinishga ega:

Download 0.91 Mb.

Do'stlaringiz bilan baham:
1   ...   25   26   27   28   29   30   31   32   ...   49




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