kyamaliev

CountNumbersByValue

Nov 26th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CountOfDifferentIntegers
  8. {
  9.     class CountOfNumbers
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] arr = new int[] { -2, 1, 3, -5, 0, 9, 0, -6, -102 };
  14.             int countOfPositive = 0;
  15.             int countOfNegative = 0;
  16.             int countOfZero = 0;
  17.  
  18.             for (int i = 0; i < arr.Length; i++)
  19.             {
  20.                 if (arr[i] > 0)
  21.                 {
  22.                     countOfPositive++;
  23.                 }
  24.                 else if (arr[i] < 0)
  25.                 {
  26.                     countOfNegative++;
  27.                 }
  28.                 else
  29.                 {
  30.                     countOfZero++;
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine("Number of positive numbers: " + countOfPositive);
  35.             Console.WriteLine("Number of negative numbers: " + countOfNegative);
  36.             Console.WriteLine("Number of zeros: " + countOfZero);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment