Advertisement
Masovski

[C# Basics][Loops-HW] 10. Odd and Even Product

Mar 29th, 2014
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2.  
  3. class OddOrEvenProduct
  4. {
  5.     static void Main()
  6.     {
  7.         string input = Console.ReadLine();
  8.         string[] splitedNumbers = input.Split(' ');
  9.         int oddProduct = 1;
  10.         int evenProduct = 1;
  11.  
  12.         for (int i = 0; i < splitedNumbers.Length; i++)
  13.         {
  14.             int tempNumber = int.Parse(splitedNumbers[i]);
  15.             bool isOdd = (i + 1) % 2 != 0;
  16.             bool isEven = (i + 1) % 2 == 0;
  17.  
  18.             if (isOdd)
  19.             {
  20.                 oddProduct *= tempNumber;
  21.             }
  22.             if (isEven)
  23.             {
  24.                 evenProduct *= tempNumber;
  25.             }  
  26.         }
  27.         if (oddProduct == evenProduct)
  28.         {
  29.             Console.WriteLine("yes");
  30.             Console.WriteLine("The product is {0}", oddProduct);
  31.         }
  32.         else
  33.         {
  34.             Console.WriteLine("no");
  35.             Console.WriteLine("Odd product is {0}", oddProduct);
  36.             Console.WriteLine("Even product is {0}", evenProduct);
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement