Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Task4
- {
- public class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = { 4, 1, 9, -3, 7 };
- if (numbers.Length == 0)
- {
- Console.WriteLine("Массив пуст");
- return;
- }
- Console.Write("Массив: ");
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.Write(numbers[i] + ", ");
- }
- int min = FindMin(numbers);
- int max = FindMax(numbers);
- Console.WriteLine($"\nМинимум: {min}\nМаксимум: {max}");
- }
- static int FindMin(int[] arr)
- {
- int min = arr[0];
- foreach (int num in arr)
- {
- if (num < min)
- {
- min = num;
- }
- }
- return min;
- }
- static int FindMax(int[] arr)
- {
- int max = arr[0];
- foreach (int num in arr)
- {
- if (num > max)
- {
- max = num;
- }
- }
- return max;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement