2
06/11/2024 6:38 pm
Topic starter
Please help me find a way to calculate 5 numbers - each on one line (NOT ON A DIFFERENT) in C#. I am a newbie - and I am confused with this task! Thanks
1 Answer
2
06/11/2024 6:39 pm
You must put them in an array - and since you know how many elements you will have in the array - the calculation should be easy! You should only parse the numerical value.
Here it is:
using System; class SumOfFiveNumbers { static void Main() { string[] numbers = Console.ReadLine().Split(' '); decimal a = decimal.Parse(numbers[0]); decimal b = decimal.Parse(numbers[1]); decimal c = decimal.Parse(numbers[2]); decimal d = decimal.Parse(numbers[3]); decimal e = decimal.Parse(numbers[4]); Console.WriteLine(a+b+c+d+e); } }