Advertisement
dim4o

Loops_10_OddAndEvenProduct

Mar 26th, 2014
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             string input = Console.ReadLine();
  4.             string[] array = input.Split(' ');
  5.             int oddProduct = 1;
  6.             int evenProduct = 1;
  7.          
  8.             for (int index = 0; index < array.Length; index++)
  9.             {
  10.                 int number = int.Parse(array[index]);
  11.                 if (index %2 == 0 || index == 0)
  12.                 {
  13.                     oddProduct *= number;
  14.                 }
  15.                 else
  16.                 {
  17.                     evenProduct *= number;
  18.                 }
  19.             }
  20.             if (oddProduct == evenProduct)
  21.             {
  22.                 Console.WriteLine("yes");
  23.                 Console.WriteLine("product = {0}", oddProduct);
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("no");
  28.                 Console.WriteLine("odd procuct = {0}", oddProduct);
  29.                 Console.WriteLine("even procuct = {0}", evenProduct);
  30.             }          
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement