Advertisement
vovanhik_24

Task 4

Apr 8th, 2025 (edited)
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Task4
  4. {
  5.     public class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] numbers = { 4, 1, 9, -3, 7 };
  10.  
  11.             if (numbers.Length == 0)
  12.             {
  13.                 Console.WriteLine("Массив пуст");
  14.                 return;
  15.             }
  16.  
  17.             Console.Write("Массив: ");
  18.             for (int i = 0; i < numbers.Length; i++)
  19.             {
  20.                 Console.Write(numbers[i] + ", ");
  21.             }
  22.  
  23.             int min = FindMin(numbers);
  24.             int max = FindMax(numbers);
  25.  
  26.             Console.WriteLine($"\nМинимум: {min}\nМаксимум: {max}");
  27.         }
  28.  
  29.         static int FindMin(int[] arr)
  30.         {
  31.             int min = arr[0];
  32.  
  33.             foreach (int num in arr)
  34.             {
  35.                 if (num < min)
  36.                 {
  37.                     min = num;
  38.                 }
  39.             }
  40.  
  41.             return min;
  42.         }
  43.  
  44.         static int FindMax(int[] arr)
  45.         {
  46.             int max = arr[0];
  47.  
  48.             foreach (int num in arr)
  49.             {
  50.                 if (num > max)
  51.                 {
  52.                     max = num;
  53.                 }
  54.             }
  55.  
  56.             return max;
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement