Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication8
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int n = 5;
- int[] arr = new int[n];
- Random rnd = new Random();
- Console.WriteLine("Original array: ");
- for (int i = 0; i < n; ++i)
- {
- arr[i] = rnd.Next(-10,10);
- Console.Write(" " + arr[i]);
- }
- int max = arr[0];
- for (int i = 0; i < n; ++i)
- if (Math.Abs(arr[i]) > max)
- max = Math.Abs(arr[i]);
- Console.WriteLine("\nMax element: " + max);
- int sum = 0;
- int el_1 = arr[0], el_2 = arr[0];
- int pos_1 = 0, pos_2 = 0;
- for (int i = 0; i < n; ++i)
- {
- if (arr[i] > 0)
- {
- el_1 = arr[i];
- pos_1 = i;
- }
- break;
- }
- for (int i = pos_1 + 1; i < n; ++i)
- {
- if (arr[i] > 0)
- {
- el_2 = arr[i];
- pos_2 = i;
- }
- }
- //if (pos_2 - pos_1 > 1)
- for (int i = pos_1 + 1; i < pos_2; ++i )
- sum += arr[i];
- Console.WriteLine("Summary: " + sum);
- }
- }
- }
Add Comment
Please, Sign In to add comment