Advertisement
remote87

Odd and Even Product

Sep 7th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 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 _10.OddAndEvenProduct
  8. {
  9.     class OddAndEvenProduct
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.Write("Enter numbers separated by space: ");
  14.             string[] numbers = Console.ReadLine().Split();
  15.             int productEven = 1;
  16.             int productOdd = 1;
  17.             for (int i = 0; i <= numbers.Length - 1;)
  18.             {
  19.                 productOdd *= Convert.ToInt32(numbers[i]);
  20.                 i += 2;
  21.             }
  22.             for (int j = 1; j <= numbers.Length - 1;)
  23.             {
  24.                 productEven *= Convert.ToInt32(numbers[j]);
  25.                 j += 2;
  26.             }
  27.             bool equal = (productEven == productOdd);
  28.             Console.WriteLine("Result: {0}.", equal);
  29.             if (equal)
  30.             {
  31.                 Console.WriteLine("Product: {0}.", productEven);
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine("Even product: {0}.", productEven);
  36.                 Console.WriteLine("Odd product: {0}.", productOdd);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement