Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _8._Condense_Array_to_Number
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.  
  12. int sum = 0;
  13. if (nums.Length == 1)
  14. {
  15. Console.WriteLine(nums[0]); return;
  16. }
  17. while ((nums.Length-1) >= 1)
  18. {
  19.  
  20. int[] condensed = new int[nums.Length - 1];
  21. for (int i = 0; i < nums.Length-1; i++)
  22. {
  23.  
  24. sum = nums[i] + nums[i + 1];
  25. condensed[i] = sum;
  26.  
  27. }
  28. nums = condensed;
  29. }
  30. Console.WriteLine(sum);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement