Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You are given n integers (given in a single line, separated by a space). Write a program that checks whether the product of the odd elements is equal to the product of the even elements. Elements are counted from 1 to n, so the first element is odd, the second is even, etc.
- Ето ги моите и спагети:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class OddAndEven
- {
- static void Main(string[] args)
- {
- string n = Console.ReadLine();
- string[] splitter = n.Split(' ');
- int oddProduct = 1;
- int evenProduct = 1;
- for (int i = 0; i < splitter.Length; i++)
- {
- int num = Convert.ToInt32(splitter[i]);
- if (num % 2 != 0)
- {
- int oddNum = num;
- oddProduct *= oddNum;
- }
- if (num % 2 == 0)
- {
- int evenNum = num;
- evenProduct *= evenNum;
- }
- }
- if (oddProduct == evenProduct)
- {
- Console.WriteLine("yes");
- Console.WriteLine("The product is {0}", oddProduct);
- }
- else
- {
- Console.WriteLine("no");
- Console.WriteLine("Odd product is {0}", oddProduct);
- Console.WriteLine("Even product is {0}", evenProduct);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement