qustion max min

  • Thread starter Thread starter Ofri Cachlon
  • Start date Start date
O

Ofri Cachlon

Guest
:the question

Write a program that accepts 10 numbers. The program will display as the output
A. The smallest positive number.
B. The largest negative number.

someone can tell me what wrong

Thanks in advance(:

{
double max;
double min;
double num;
bool check=true;

Console.WriteLine("enter 10 numbers");
min = double.Parse(Console.ReadLine());
max = min;
for (int i = 1; i <= 10; i++)
{
num = double.Parse(Console.ReadLine());
if (num > 0)
{
check = true;
}
if (num < 0)
{
check = false;
}
if (check == true && num < max)
{
max = Math.Max(max, num);
}
if (check == false && min < num)
{
min = Math.Max(num, min);
}
}
Console.WriteLine("max= " + max);
Console.WriteLine("min= " + min);

}

Continue reading...
 
Back
Top