---
title: "Finding the minimum value in c#"  
description: "Finding the minimum value in c#"  
author: "Lady Bird Johnson"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1606/finding-the-minimum-value-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Finding the minimum value in c#

I have this pretty [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
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](https://www.mindstick.com/forum/33920/what-is-different-var-and-dynamic-types-in-c-sharp) pcm and maxm([maximum value](https://www.mindstick.com/forum/33667/select-the-maximum-value-of-a-colum-in-mysql)), 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 maxim(maximum value). how could I do that?\

## Replies

### Reply by Madam Walker

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();
}
```


---

Original Source: https://www.mindstick.com/forum/1606/finding-the-minimum-value-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
