FINDING THE MINIMUM VALUE IN C#

Lady Bird Johnson

Total Post:20

Points:140
Posted by  Lady Bird Johnson
C# 
C#
 1105  View(s)
Ratings:
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?

  1. Madam Walker

    Post:22

    Points:154
    Re: Finding the minimum value in c#

    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();
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!