Venciity

[Jumpstart C#] ArraysAndLists TASK17

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