static void Minmax1() { int N = 7, min = 0, max = 0, a = -100, b = 100; int[] A = Gen.ArrayIntAB(a, b, N); Output.WriteLine(A); Console.WriteLine(); foreach (int x in A) { min = (min > x ? x : min); max = (max < x ? x : max); } Console.Write(min + " " + max); }
static void Minmax4() { int N = 7, min_pos = 0, max_pos = 0, min, max, a = -100, b = 100; int[] A = Gen.ArrayIntAB(a, b, N); Output.WriteLine(A); Console.WriteLine(); min = A[0]; max = A[0]; for (int x = 0; x < N; x++) { min_pos = (min > A[x] ? x : min_pos); max_pos = (max < A[x] ? x : max_pos); min = (min > A[x] ? A[x] : min); max = (max < A[x] ? A[x] : max); } Console.Write("min " + min_pos + " max " + max_pos + " "); }
static bool Series10() { int N = 7, A = -10, B = 10; int[] M = Gen.ArrayIntAB(A, B, N); Output.WriteLine(M); Console.WriteLine(); foreach (int x in M) { if (x > 0) { Console.WriteLine("true"); return(true); } } Console.WriteLine("true"); return(false); }
static void Minmax3() { int N = 7, min = 0, max = 0, a = -100, b = 100, num1 = 0, num2 = 0; int[] A = Gen.ArrayIntAB(a, b, 2 * N); Output.WriteLine(A); Console.WriteLine(); for (int y = 0; y < N * 2; y += 2) { Console.Write(2 * A[y] + 2 * A[y + 1] + " "); } Console.WriteLine(); for (int x = 0; x < N * 2; x += 2) { num1 = A[x]; num2 = A[x + 1]; min = (min > 2 * num1 + 2 * num2 ? 2 * num1 + 2 * num2 : min); max = (max < 2 * num1 + 2 * num2 ? 2 * num1 + 2 * num2 : max); } Console.Write(min + " " + max); }