Advertisement
Nikolay_Kashev

Min/Max values in range

Mar 2nd, 2024
1,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.39 KB | Software | 0 0
  1. int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  2.  
  3. int start = int.Parse(Console.ReadLine());
  4. int end = int.Parse(Console.ReadLine());
  5.  
  6. int max = int.MinValue;
  7. int min = int.MaxValue;
  8.  
  9. for (int i = start; i <= end; i++)
  10. {
  11.     if (nums[i] > max)
  12.         max = nums[i];
  13.  
  14.     if (nums[i] < min)
  15.         min = nums[i];
  16. }
  17.  
  18. int sum = max + min;
  19. Console.WriteLine(sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement