how to find the min and the max and its position without using math+ while using while

  • Thread starter Thread starter mmay172
  • Start date Start date
M

mmay172

Guest
I wrote

using System;
class MainClass
{
public static void Main (string[] args)
{
int max=0,min=0,minp=0,maxp=0,num;
Console.Write("give me a positive number: ");
num=int.Parse(Console.ReadLine());
while(num!=0)
{
if(num!=0)
{
if(max<num)
{
max=num;
maxp++;
}
if(min>num)
{
min=num;
minp++;
}
Console.Write("give me a positive number: ");
num=int.Parse(Console.ReadLine());
}
}
Console.WriteLine("the Max is: {0} and his position is:{1}",max,maxp);
Console.WriteLine("the Min is: {0} and his position is: {1}",min,minp);
}

}

and the result was when I entered:

2,4,6,9,0

The Max is : 9 and his position is : 4

The Min is : 0 and his position is : 0

how to make it right?..









Continue reading...
 
Back
Top