Advertisement
vladeto87

OddAndEvenProduct

Apr 4th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 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.  
  8. class OddAndEvenProduct
  9. {
  10.     static void Main()
  11.     {
  12.         Console.Write("Enter n = ");
  13.         int n = int.Parse(Console.ReadLine());
  14.         int[] numbers = new int[n];
  15.         for (int i = 0; i < numbers.Length; i++)
  16.             numbers[i] = int.Parse(Console.ReadLine());
  17.  
  18.        
  19.        
  20.        
  21.             int productODD = 1;
  22.             for (int i = 0; i <= n-1  ; i += 2)
  23.             {
  24.                 productODD *= numbers[i];
  25.             }
  26.            
  27.             int productEven = 1;
  28.                 for (int i = 1; i <= n - 1; i += 2)
  29.                 {
  30.                     productEven *= numbers[i];
  31.                 }
  32.            
  33.            if (productODD == productEven)
  34.            {
  35.                Console.WriteLine("yes");
  36.                Console.WriteLine("product = {0}", productEven);
  37.            }
  38.            if (productODD != productEven)
  39.            {
  40.                Console.WriteLine("no");
  41.                Console.WriteLine("odd_product = {0}", productODD);
  42.                Console.WriteLine("even_product = {0}", productEven);
  43.            }
  44.  
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement