JulianJulianov

01. Train Array

Feb 5th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. 01. Train
  2. You will be given a count of wagons in a train n. On the next n lines you will receive how many people are going to get on each wagon. At the end print the whole train and after that, on the next line, the sum of the people in the train.
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace _01Train
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. var countTrain = int.Parse(Console.ReadLine());
  17. //int sumPeople = 0;
  18. int[] train = new int[countTrain];
  19. for (int i = 0; i < countTrain; i++)
  20. {
  21. train[i] = int.Parse(Console.ReadLine());
  22. //sumPeople += train[i];
  23. }
  24. Console.WriteLine(string.Join(" ", train));
  25. Console.WriteLine(/*sumPeople*/train.Sum());// Чрез .Sum() стават излишни, по-горе, два реда!
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment