mirror of
https://github.com/KhasanovAMdev/ISTU_TEST_LR1.git
synced 2026-02-03 00:19:35 +04:00
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
internal class Program
|
||
{
|
||
private static float[] inputArray = {
|
||
1.5f, -2.4f, 3.1f, 0.5f, 12.7f, -8.2f, 4.4f, 9.0f, 01511.0f
|
||
};
|
||
private static void Main()
|
||
{
|
||
Console.WriteLine($"Массив с входными данными: [{string.Join("; ", inputArray)}]");
|
||
|
||
var outputData = ArrayProc(inputArray);
|
||
|
||
Console.WriteLine($"Массив с выходными данными: [{string.Join("; ", outputData ?? Array.Empty<float>())}]");
|
||
}
|
||
|
||
|
||
private static float[]? ArrayProc(float[] inputData)
|
||
{
|
||
float[] outputArray;
|
||
int pairs = 0;
|
||
int n = inputData.Length - 1;
|
||
for (int i = 0; i <= n / 2; i++)
|
||
{
|
||
if (i + 8 <= n) pairs++;
|
||
}
|
||
|
||
if (pairs == 0)
|
||
{
|
||
Console.WriteLine("Размер массива не соответствует условию");
|
||
return null;
|
||
}
|
||
|
||
outputArray = new float[pairs];
|
||
|
||
for (int i = 8, j = 0; j < outputArray.Length; j++, i++)
|
||
{
|
||
outputArray[j] = inputData[i] * inputData[i - 8];
|
||
}
|
||
|
||
if (outputArray.Length % 2 != 0)
|
||
{
|
||
int centralIdx = outputArray.Length / 2;
|
||
float centralItem = outputArray[centralIdx];
|
||
outputArray[centralIdx] = centralItem * centralItem;
|
||
}
|
||
return outputArray;
|
||
}
|
||
|
||
} |