using System;
namespace BrainlyTask {
class Program {
public static int FindIndMaxSeqWith3Elem(int[] arr) {
int previous1 = 0, previous2 = 0, ind = 0;
int max = 0, maxind = 0;
var it = arr.GetEnumerator();
if (it.MoveNext())
previous2 = Convert.ToInt32(it.Current);
if (it.MoveNext()) {
previous1 = previous2;
previous2 = Convert.ToInt32(it.Current);
}
while (it.MoveNext()) {
var sum = previous1 + previous2 + Convert.ToInt32(it.Current);
if (sum > max) {
max = sum;
maxind = ind;
}
previous1 = previous2;
previous2 = Convert.ToInt32(it.Current);
ind++;
}
return maxind;
}
static void Main(string[] args) {
var arr = new int[15];
Random rand = new Random();
for (int i=0; i
arr[i] = rand.Next(1,1000);
Console.Write(arr[i]+" ");
}
Console.WriteLine();
Console.WriteLine(FindIndMaxSeqWith3Elem(arr));
}
}
}
Пример в приложении.
Критика в комментарии..