Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. class zadacha227
  2. {
  3. static int[] FillArray(int n)
  4. {
  5. int[] array = new int[n];
  6. for (int i = 0; i < array.Length; i++)
  7. {
  8. array[i] = int.Parse(Console.ReadLine());
  9. }
  10. return array;
  11. }
  12. static int CalculateSum(int[] array)
  13. {
  14. int sum = 0;
  15. for (int i = 0; i < array.Length; i++)
  16. {
  17. sum += array[i];
  18. }
  19. return sum;
  20. }
  21.  
  22. static int CalculateProduct(int[] array)
  23. {
  24. int product = 1;
  25. for (int i = 0; i < array.Length; i++)
  26. {
  27. product *= array[i];
  28. }
  29. return product;
  30. }
  31. static void Main(string[] args)
  32. {
  33. Console.Write("Въведете дължина на масива: ");
  34. int n = int.Parse(Console.ReadLine());
  35. int[] array = FillArray(n);
  36. Console.Write("Сумата на елементите на масива е: ");
  37. Console.WriteLine(CalculateSum(array));
  38. Console.Write("Произведението на елементите на масива е: ");
  39. Console.WriteLine(CalculateProduct(array));
  40. Console.ReadKey(true);
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement