0
How to find the smallest number in an array?
I attempted to make a code where: -only accepts upto 50 integers -ignores negative numbers -Takes 0 (zero) as a sentinel value -computes the sum -displays the largest and smallest number I have made a code, my only problem is that is displays the sentinel value as its smallest number. How do I ignore the sentinel value when taking the smallest number? https://code.sololearn.com/cVpf4LjAikrB/?ref=app
2 Antworten
+ 2
You already sorted the array in a way. So to get the minimum value you only refer index zero. To get the maximum value refer to index <count> - 1.
min = arr[ 0 ];
max = arr[ count- 1 ];
+ 1
You can use if and continue to ignore a certain number.
This condition has to be the first:
if(arr[index] == sentinel){
continue;
}