Guest User

Untitled

a guest
Nov 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication8
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. const int n = 5;
  13. int[] arr = new int[n];
  14. Random rnd = new Random();
  15. Console.WriteLine("Original array: ");
  16. for (int i = 0; i < n; ++i)
  17. {
  18. arr[i] = rnd.Next(-10,10);
  19. Console.Write(" " + arr[i]);
  20. }
  21.  
  22. int max = arr[0];
  23. for (int i = 0; i < n; ++i)
  24. if (Math.Abs(arr[i]) > max)
  25. max = Math.Abs(arr[i]);
  26. Console.WriteLine("\nMax element: " + max);
  27.  
  28. int sum = 0;
  29. int el_1 = arr[0], el_2 = arr[0];
  30. int pos_1 = 0, pos_2 = 0;
  31.  
  32. for (int i = 0; i < n; ++i)
  33. {
  34. if (arr[i] > 0)
  35. {
  36. el_1 = arr[i];
  37. pos_1 = i;
  38. }
  39. break;
  40. }
  41. for (int i = pos_1 + 1; i < n; ++i)
  42. {
  43. if (arr[i] > 0)
  44. {
  45. el_2 = arr[i];
  46. pos_2 = i;
  47. }
  48. }
  49.  
  50. //if (pos_2 - pos_1 > 1)
  51. for (int i = pos_1 + 1; i < pos_2; ++i )
  52. sum += arr[i];
  53. Console.WriteLine("Summary: " + sum);
  54. }
  55. }
  56. }
Add Comment
Please, Sign In to add comment