Python:
def sorting(*args):
print(*sorted(args))
sum = 0
for i in args:
sum += i * i
print(sum)
sorting(8, 4, 6)
Объяснение:
Задача1
массив определи как array[];
чтобы посчитать, просто используй счетчик, но сначала инициализируй переменную, которая содержит ответ задачи:
int n;
array [n];
int answer;
for (i=0, i < n, i++)
{
if (array[i] == 2)
answer++;
}
std::cout<<answer;
Как то так
Задача2
array[n];
for (int i =1, i < n, i++)
{
if (array[0] >= array[i])
array[0] = array[i];
}
std::cout << array[0];
//Это было решение первого пункта
int first;
int last
bool positive;
while (positive == false )
{
for (int i = 0; i < n; i++)
{
if (array[i] > 0)
{
positive = true;
first = i;
array[i] = -1;
}
}
while (positive == false )
{
for (int i = 0, i < n, i++)
{
if (array[i] > 0)
{
positive = true;
last = i;
}
}
int summ
for (int i = first, i < last, i++)
{
summ += array[i];
}
std::cout<<summ; // ответ на 2 пункт
// ПРеобразую
newarray [n];
int a = 0;
for (int i = 0, i < n, i++)
{
if (array[i] == 0)
{
newarray[a] = array[i];
a++;
}
}
for (int i = 0, i < n, i++)
{
if (array[i] != 0)
{
newarray[a] = array[i];
a++;
}
}
std::cout<< newarray;
C#
double a, b, c, s;
ConsoleKeyInfo keyInfo;
do
{
Console.Write("Введите первое число: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите второе число: ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите третее число: ");
c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("");
if (a < b && a < c)
{
Console.WriteLine(a);
Console.WriteLine(Math.Min(b, c));
Console.WriteLine(Math.Max(b, c));
}
if (b < a && b < c)
{
Console.WriteLine(b);
Console.WriteLine(Math.Min(a, c));
Console.WriteLine(Math.Max(a, c));
}
if (c < b && c < a)
{
Console.WriteLine(c);
Console.WriteLine(Math.Min(a, b));
Console.WriteLine(Math.Max(a, b));
}
Console.WriteLine("");
a = Math.Pow(a, 2);
b = Math.Pow(b, 2);
c = Math.Pow(c, 2);
if (a < b && a < c)
{
Console.WriteLine(a);
Console.WriteLine(Math.Min(b, c));
Console.WriteLine(Math.Max(b, c));
}
if (b < a && b < c)
{
Console.Write(b);
Console.WriteLine(Math.Min(a, c));
Console.WriteLine(Math.Max(a, c));
}
if (c < b && c < a)
{
Console.Write(c);
Console.WriteLine(Math.Min(a, b));
Console.WriteLine(Math.Max(a, b));
}
Console.WriteLine("");
s = a + b + c;
Console.WriteLine("" + s + "\n");
Console.WriteLine("Если хотите повторить программу нажмите F");
Console.WriteLine("Если хотите завершить программу нажмите любую другую кнопку\n");
keyInfo = Console.ReadKey(true);
}
while (keyInfo.Key == ConsoleKey.F);