Hi There,
I'm playing around with different possibilities to test an array for the biggest and smallest numbers… I know this one is far from the best, but I’m just trying to understand why doesn't it work. It should be able to identify the highest num as long as it's positive and the lowest as long as it's smaller than 200 but still, it finds only the highest one and keeps telling me the lowest is 0.
Any help or tips would be much appreciated!
insert
Code:
#include <stdio.h>
main()
{
int arr[100];
int num;
int cntr=0;
int testH=0;
int testL=200;
printf("Enter the number of elements you would like to test \n");
scanf(" %d", &num);
for(cntr ; cntr+1 <= num ; ++cntr)
{
printf("Enter indigent number %d: ", cntr+1);
scanf(" %d", &arr[cntr]);
}
for(cntr=0 ; cntr <= num ; ++cntr){
if(arr[cntr] <= testL)
testL=arr[cntr];
if(arr[cntr] >= testH)
testH=arr[cntr];
}
printf("Highest number is %d\n", testH);
printf("Lowest number is %d", testL);
return(0);
}