Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. 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.
  2.  
  3.  
  4. Ето ги моите и спагети:
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12.  
  13. class OddAndEven
  14. {
  15. static void Main(string[] args)
  16. {
  17. string n = Console.ReadLine();
  18. string[] splitter = n.Split(' ');
  19. int oddProduct = 1;
  20. int evenProduct = 1;
  21.  
  22. for (int i = 0; i < splitter.Length; i++)
  23. {
  24. int num = Convert.ToInt32(splitter[i]);
  25.  
  26. if (num % 2 != 0)
  27. {
  28. int oddNum = num;
  29. oddProduct *= oddNum;
  30. }
  31. if (num % 2 == 0)
  32. {
  33. int evenNum = num;
  34. evenProduct *= evenNum;
  35. }
  36. }
  37.  
  38. if (oddProduct == evenProduct)
  39. {
  40. Console.WriteLine("yes");
  41. Console.WriteLine("The product is {0}", oddProduct);
  42. }
  43. else
  44. {
  45. Console.WriteLine("no");
  46. Console.WriteLine("Odd product is {0}", oddProduct);
  47. Console.WriteLine("Even product is {0}", evenProduct);
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement