Venciity

[Jumpstart C#] ArraysAndLists TASK19

Feb 25th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. /*Задача М1-19.
  2.  * Да се намери сред­ноа­рит­ме­тичното и броя на всички от­ри­ца­тел­ни еле­менти на масив A(N) след първия елемент = 0.     */
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace task19
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.Write("Enter array length: ");
  17.             int length = int.Parse(Console.ReadLine());
  18.             int[] myArray = new int[length];
  19.  
  20.             //enter array elements
  21.             for (int index = 0; index < myArray.Length; index++)
  22.             {
  23.                 Console.Write("Number {0} = ", index + 1);
  24.                 myArray[index] = int.Parse(Console.ReadLine());
  25.             }
  26.  
  27.             int i = 0;
  28.             while (i < myArray.Length && myArray[i] != 0)
  29.             {
  30.                 i++;
  31.             }
  32.  
  33.             int sum = 0;
  34.             int count = 0;
  35.             for (int j = i+1; j < myArray.Length; j++)
  36.             {
  37.                 if (myArray[j] < 0)
  38.                 {
  39.                     sum += myArray[j];
  40.                     count++;
  41.  
  42.                 }
  43.             }
  44.  
  45.             Console.WriteLine("Average = {0} count = {1}",sum/(float)count, count);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment