0

How do I display the largest number in an array without sorting out the whole array?

Arrays in C++

24th Feb 2017, 12:09 PM
Benedictus Yayra Tsrakasu
Benedictus Yayra Tsrakasu - avatar
4 Réponses
+ 3
take first element of array, initialize in variable max..compare it by all other values of array and if getting greater value of max, update max..keep doing this till last element. or you can use max function in some languages.
24th Feb 2017, 12:31 PM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 1
simple just compare..it...like for(int i=0;i<a.length;i++) if(a[i]>a[i+1]) max=a[i]; else max=a[i+1];
24th Feb 2017, 3:38 PM
Deepak Sharma
Deepak Sharma - avatar
0
thanks guys
26th Feb 2017, 10:12 PM
Benedictus Yayra Tsrakasu
Benedictus Yayra Tsrakasu - avatar