Почему не считает сумму ? - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Для массива чисел из задачи 1 вычислить кубический корень каждого элемента и сумму элементов образованного массива.
namespace Alg_Laba2._2
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[100];
for (int i = 0; i < 100; i++)
{
array[i] = (int)Math.Pow(i + 1, 3);
}
for (int i = 0; i < 100; i++)
{
Console.Write("{0,10}", array[i]); //это задача номер 1
if ((i + 1) % 10 == 0)
Console.WriteLine();
}
int sum = 0;
foreach (int elem in array)
if (elem > 0)
sum = +elem;
Console.WriteLine("Suma= " + sum);
Console.ReadKey();
}
}
}Решение задачи: «Почему не считает сумму ?»
textual
Листинг программы
sum += elem;