Answer the question
In order to leave comments, you need to log in
How, in a one-dimensional array of integer array of size 10, to replace the positive element with the minimum, and the negative element with the minimum?
static void Main(string[] args)
{
Console.WriteLine("enter array dimension");
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; ++i)
{
Console.Write("a[{0}]= ", i);
a[i] = int.Parse(Console.ReadLine());
}
double max = a[0];
for (int i = 1; i < a.Length; i++)
if (a[i] < 0 && a[i] > max)
max = a[i];
Console.WriteLine("Maximum among negatives: " + max);
Console.ReadKey();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question