svetlozar_kirkov

Integers separated sum (Exercise)

Oct 8th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleTests
  6. {
  7.     class ConsoleTests
  8.     {
  9.         static void Main()
  10.         {
  11.             Console.Write("Enter numbers (separated by space): ");
  12.             string input = Console.ReadLine();
  13.             string[] nums = input.Split(' ').ToArray();
  14.             int[] numbers = new int[nums.Length];
  15.             for (int i = 0; i < numbers.Length; i++)
  16.             {
  17.                 numbers[i] = Convert.ToInt32(nums[i]);
  18.             }
  19.             Console.WriteLine("Sum = {0}",numbers.Sum());
  20.         }
  21.  
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment