Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Linked List
Exemplu OOP inventar
trees with reverse polish notation
2 point gradient (v2)
30272 Program Ex5 if_else_odd_even
Task 1_4
modified
Enumeration
Free v Bucks Codes
UnityCubo
Please log in to post a comment.