Числа отрицательные. Нужно их поменять в положительные - C#
Формулировка задачи:
class Program
{
static void Main(string[] args)
{
double[] arr = new double[15];
int Y = 0;
for (int x = -5; x <= 10; x++)
{
arr[Y] = Math.Cos(x) - Math.Cos(x * 2);
if (arr[Y] < 0)
{
Console.Write(arr[Y] + "\t");
}
}
Console.ReadKey();\\ Console.Write(arr[Y] + "\t"); как результат отрицательных поменять в положительные ?
Решение задачи: «Числа отрицательные. Нужно их поменять в положительные»
textual
Листинг программы
static void Main(string[] args)
{
int[] arr = new int[] { 1, -3, 5, -7, 9, -11 };
for(int i =0;i<arr.Length;i++)
{
if(arr[i]<0)
{
Console.WriteLine(arr[i] * -1);
}
else
{
Console.WriteLine(arr[i]);
}
}
Console.ReadKey();
}