Skip to content

Instantly share code, notes, and snippets.

@KirillJJ
Created June 20, 2020 16:36
Show Gist options
  • Save KirillJJ/99270deedf0a03d382b73c8913baf43f to your computer and use it in GitHub Desktop.
Save KirillJJ/99270deedf0a03d382b73c8913baf43f to your computer and use it in GitHub Desktop.
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
First();
Second();
Third();
Fourth();
}
static void First()
{
Console.WriteLine("Введите массив чисел через пробел");
string s = Console.ReadLine();
if (s == null || s.Length == 0) return;
string[] arr = s.Split(separator: ' ');
int[] arr2 = new int[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
arr2[i] = int.Parse(arr[i]);
}
int sum = 0;
for (int i = 0; i < arr2.Length - 1; i++)
{
sum += arr2[i] * arr2[i + 1];
}
Console.WriteLine(sum);
}
static void Second()
{
Console.WriteLine("Введите массив чисел через пробел");
string s = Console.ReadLine();
if (s == null || s.Length == 0) return;
string[] arr = s.Split(separator: ' ');
int[] arr2 = new int[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
arr2[i] = int.Parse(arr[i]);
}
Console.WriteLine("Введите число");
int n = int.Parse(Console.ReadLine());
int maxIndex = 0;
int maxValue = Int32.MinValue;
for (int i = 0; i < arr2.Length; i++)
{
if (arr2[i] > maxValue)
{
maxIndex = i;
maxValue = arr2[i];
}
}
int[] newArr = new int[arr2.Length + 1];
for (int i = 0; i < newArr.Length - 1; i++)
{
if (i < maxIndex)
{
newArr[i] = arr2[i];
}
else
{
if (i == maxIndex)
{
newArr[i] = arr2[i];
newArr[i + 1] = n;
}
else
{
newArr[i + 1] = arr2[i];
}
}
}
Console.WriteLine(string.Join(' ', newArr));
}
static void Third()
{
Console.WriteLine("Введите массив чисел через пробел");
string s = Console.ReadLine();
if (s == null || s.Length == 0) return;
string[] arr = s.Split(separator: ' ');
int[] arr2 = new int[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
arr2[i] = int.Parse(arr[i]);
}
int minIndex = 0;
int minValue = Int32.MaxValue;
for (int i = 0; i < arr2.Length; i++)
{
if (arr2[i] < minValue)
{
minIndex = i;
minValue = arr2[i];
}
}
int[] newArr = new int[arr2.Length - 1];
for (int i = 0; i < newArr.Length; i++)
{
if (i < minIndex)
{
newArr[i] = arr2[i];
}
else
{
if (i >= minIndex)
{
newArr[i] = arr2[i + 1];
}
}
}
Console.WriteLine(string.Join(' ', newArr));
}
static void Fourth()
{
Console.WriteLine("Введите массив чисел через пробел");
string s = Console.ReadLine();
if (s == null || s.Length == 0) return;
string[] arr = s.Split(separator: ' ');
int[] arr2 = new int[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
arr2[i] = int.Parse(arr[i]);
}
int minValue = Int32.MaxValue;
for (int i = 0; i < arr2.Length; i++)
{
if (arr2[i] < minValue)
{
minValue = arr2[i];
}
}
Console.WriteLine(minValue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment