Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01. Train
- 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.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _01Train
- {
- class Program
- {
- static void Main(string[] args)
- {
- var countTrain = int.Parse(Console.ReadLine());
- //int sumPeople = 0;
- int[] train = new int[countTrain];
- for (int i = 0; i < countTrain; i++)
- {
- train[i] = int.Parse(Console.ReadLine());
- //sumPeople += train[i];
- }
- Console.WriteLine(string.Join(" ", train));
- Console.WriteLine(/*sumPeople*/train.Sum());// Чрез .Sum() стават излишни, по-горе, два реда!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment