Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that enters 5 numbers (given in a single line, separated by a space), calculates and prints their sum.
- using System;
- using System.Text.RegularExpressions;
- class Sum5Numbers
- {
- static void Main()
- {
- Console.Write("Enter Five numbers with spaces:");
- string numFive = Console.ReadLine();
- numFive = Regex.Replace(numFive, @"\s+", " ");
- string[] numbers = numFive.Split(' ');
- double sum = 0.0;
- foreach (string number in numbers)
- {
- double newNum = double.Parse(number);
- sum = sum + newNum;
- }
- Console.WriteLine("The sum of Five numbers is: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment