Forum guidelines
Find Largest and Smallest numbers in C# app
Posted By Adam on 16 Sep 2007
Hello all, I am working on a project for my school and I am really stumped. We have to create a console application where you are prompted to enter in 3 different numbers for the program. Well I need some help trying to get the program to find the smallest and the largest of those three numbers. Any suggestions? I've been told you need to compare number 1 to number, and then take that and compare it to number 3 but I don't know how. Can anyone help?
Re: Find Largest and Smallest numbers in C# app
Posted By Jan Montano on 16 Sep 2007  
I assume you're already familiar with loops and if conditions. Well first, you have to put those numbers in an int array then traverse that array. If we are only interested in the minimum and maximum numbers, we have to have a variable int min, and int max.

Initially, you have to assign the first number in your array to min and max. Then traverse the array.

1. Traverse array.
2. Compare if current number is less than min, then assign that number to min if it is.
3.Compare if current number is greater than max, then assign that number to max if it is.
(after traversing the loop...)
4. Display minimum and maximum numbers.

C# Corner Annual Conference 2016


Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.