Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Find smallest and largest in unsorted array
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here int [] arr = new int []{2,5,3,5,6,7,2,1,1,7}; int smallest = findSmallest(arr); Console.WriteLine(smallest); int largest = findLargest(arr); Console.WriteLine(largest); } public static int findSmallest(int[] a) { int smallest = a[0]; for(int i=1; i< a.Length; i++) { if(a[i]<smallest) smallest=a[i]; } return smallest; } public static int findLargest(int[] a) { int largest = a[0]; for(int i=1; i< a.Length; i++) { if(a[i]>largest) largest=a[i]; } return largest; } } }
run
|
edit
|
history
|
help
0
OBJ Good Start
Collatz Conjecture
reversearr
XmlException in XmlSerializer.Deserialize when XML has \0
ERGDV CSXDXS
Explanation about Aggregate method in C#
15
dairkoos
Decorator Design Pattern
MegaWays