Home > DeveloperSection > Forums > Finding the minimum value in c#
Lady Bird Johnson
Lady Bird Johnson

Total Post:20

Points:140
Posted on    October-05-2013 7:07 AM

 C# C# 
Ratings:


 1 Reply(s)
 831  View(s)
Rate this:

I have this pretty simple code:

static void Main(string[] args)
{
    int i, pcm, maxm = 0, minm = 0;
    for (i = 1; i <= 3; i++)
    {
        if (pcm > maxm)
            maxm = pcm;
        Console.WriteLine("Please enter your computer marks");
        pcm = int.Parse(Console.ReadLine());
    }
    Console.ReadKey();
}

As you can see I have the var pcm and maxm(maximum value), to find the maximum value I got this code : if (pcm > maxm) maxm = pcm;, I would like to get the minm(minimum value) in the same way I got the maxm(maximum value). how could I do that?



Madam Walker
Madam Walker

Total Post:22

Points:154
Posted on    October-05-2013 7:10 AM

Do it the same way you are doing max

 int i, pcm, maxm = 0, minm = 0;
    for (i = 1; i <= 3; i++)
    {
        if (pcm > maxm)
        {
           maxm = pcm;
        }
        if (pcm < minm)
        {
           minm = pcm;
        }
        Console.WriteLine("Please enter your computer marks");
        pcm = int.Parse(Console.ReadLine());
    }
    Console.ReadKey();
}

Don't want to miss updates? Please click the below button!

Follow MindStick