Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*b) Дан массив a[1..n] из целых чисел, принимающих значения от -1000 до 1000.
- * Найти сумму всёх чётных элементов больших среднего значения всех элементов массива.
- * Если таких нет – вывести сообщение об этом*/
- Console.WriteLine("Vvedite razmernost' massiva:");
- int n = Convert.ToInt32(Console.ReadLine());
- int[] a = new int[n];
- int sum = 0, sr=0, check=0;
- Random realRnd = new Random();
- int min = -1000, max=1000;
- for (int i = 0; i < n; i++)
- {
- a[i] = realRnd.Next(min,max);
- }
- Console.WriteLine("Sozdannyi massiv:");
- for (int i = 0; i < n; i++)
- {
- Console.Write(a[i] + " ");
- }
- for (int i = 0; i < n; i++)
- {
- sr += a[i];
- }
- for (int i = 0; i < n; i++)
- {
- if (a[i] >= sr && a[i]>=0)
- {
- sum += a[i];
- check++;
- }
- }
- if (check != 0)
- {
- Console.WriteLine("\nSumma chetnyh elementov bol'she srednego = " + sum);
- }
- else
- {
- Console.WriteLine("\nNet chetnyh elementov bol'she srednego");
- }
- Console.ReadLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement