Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /* Write a program that enters 5 numbers (given in a single line, separated by a space),
- * calculates and prints their sum. Examples:
- * numbers sum
- * 1 2 3 4 5 15
- * 10 10 10 10 10 50
- * 1.5 3.14 8.2 -1 0 11.84
- */
- class SumNumbersInLine
- {
- static void Main()
- {
- Console.WriteLine("Please, enter five numbers in line separated with space and hit \"Еnter\":");
- string input = Console.ReadLine();
- string[] numbers = input.Split(' ');
- double sumNumbers = 0;
- Console.Clear();
- try
- {
- foreach (var item in numbers)
- {
- sumNumbers = sumNumbers + double.Parse(item);
- }
- Console.WriteLine(sumNumbers);
- }
- catch (System.FormatException)
- {
- Console.WriteLine("The numbers are wrong formated!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement