L
L
Luka Tarkhnishvili2016-06-23 13:30:45
C++ / C#
Luka Tarkhnishvili, 2016-06-23 13:30:45

How to display sum of squares of numbers from ListBox?

A sequence of numbers is entered into the ListBox, for example (6,8,12). It is necessary to calculate the sum of the squares of these numbers and display in the TextBox.
I know that you don’t like such questions (write for me), but if you help me, I will be glad. I don't think it's a difficult task.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kronic, 2016-06-23
@Zorner

var array = new List<int>();
foreach (var item in myListBox.Items)
{
  array.Add(int.Parse(item.ToString()));
}
var sum = array.Sum(x => Math.Pow(x, 2));
myTextBox.Text = sum.ToString();

Transfer all values ​​from the ListBox to an array, and then
var array = new[] {6, 8, 12};
var sum = array.Sum(x => Math.Pow(x, 2));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question