27-variant
27. n ta elementdan tashkil topgan massiv berilgan. Massiv elementlari orasidan oxirgi lokal maksimum
elementi indeksini chiqaruvchi dastur tuzilsin. Lokal maksimum – o’ng va chap qo’shinisidan katta
bo’lgan element.
Javob:
int
a = Convert.ToInt32(Console.ReadLine());
double
[] ss =
new
double
[a];
for
(
int
i = 0; i < a; i++)
{
Console.Write(
"a["
+ i +
"]= "
);
ss[i] = Convert.ToDouble(Console.ReadLine());
}
Console.WriteLine(
"lokal max "
);
double
max = 0;
int
t = 0;
for
(
int
i = 1; i < a - 1; i++)
{
max = ss[i];
if
(max > ss[0] && max < ss[i + 1])
{
Console.WriteLine(i);
}
if
(max > ss[i] && max < ss[i + 2])
{
Console.WriteLine(i);
}
}
27. m x n o’lchamli matritsa berilgan. Matritsa barcha elementlari o’rta arifmetigiga, o’rta arifmetigi eng
yaqin bo’lgan satr va ustun nomerini chiqaruvchi dastur tuzilsin.
Javob:
int
m = Convert.ToInt32(Console.ReadLine());
int
n = Convert.ToInt32(Console.ReadLine());
double
[,] ss =
new
double
[m, n];
double
s = 0;
for
(
int
i = 0; i < m; i++)
{
for
(
int
j = 0; j < n; j++)
{
Console.Write(
"a["
+ i +
","
+ j +
"]= "
);
ss[i, j] = Convert.ToDouble(Console.ReadLine());
}
Console.WriteLine();
}
for
(
int
i = 0; i < m; i++)
{
for
(
int
j = 0; j < n; j++)
{
s += ss[i, j];
}
}
double
max = (
double
)s / (m * n);
Console.WriteLine(max);
int
t = 0;
for
(
int
i = 0; i < m; i++)
{
for
(
int
j = 0; j < n - 1; j++)
{
if
(max > ss[i, j] && max < ss[i, j + 1])
{
t = j + 1;
Console.WriteLine(i +
","
+ j);
Console.WriteLine(i +
","
+ t);
}
else
if
(max == ss[i, j])
{ Console.WriteLine(i +
","
+ j); }
}
Console.WriteLine();
}
27.Kamida bitta probeldan iborat satr berilgan. Satridagi birinchi va ikkinchi probel orasidagi belgilarni
chiqaruvchi dastur tuzilsin. Agar satr faqat bitta probeldan iborat bo’lsa, bo’sh satr chiqarilsin
Javob:
int
t = 0;
string
S2 =
""
;
Console.WriteLine(
"Satrni kiriting:"
);
string
S = Console.ReadLine();
for
(
int
i = 0; i < S.Length; i++)
{
if
((
int
)S[i] >= 33 && (
int
)S[i] <= 47 || (
int
)S[i] >= 58 && (
int
)S[i] <=
64 ||
(
int
)S[i] >= 91 && (
int
)S[i] <= 96 || (
int
)S[i] >= 123 && (
int
)S[i]
<= 126)
{
t++;
S2 += S[i];
}
}
if
(t == 0)
{
Console.WriteLine(
"bosh"
);
}
else
{
Console.WriteLine(S2);
}
Dostları ilə paylaş: |