Advertisement
radidim

Train (C# Shell App Paste)

Oct 1st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace Program
  8. {
  9.  
  10.     public class Train
  11.     {
  12.        public static void Main()
  13.        {
  14.         //  1.  Train
  15.         //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 the sum of the people in the train.
  16.         int n=int.Parse(Console.ReadLine());
  17.         int[] arr = new int[n];
  18.         int sum=0;
  19.         for(int i = 0;i< arr.Length;i++)
  20.         {
  21.             arr[i]=int.Parse(Console.ReadLine());
  22.             sum+=arr[i];
  23.         }
  24.         foreach(int index in arr)
  25.         {
  26.             Console.Write(index + " ");
  27.         }
  28.         Console.WriteLine(" ");
  29.         Console.WriteLine(sum);
  30.  
  31.        }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement