this code is showing the min value .
with the while loop its working fine- the min is 2
if you replace the 'while' with 'if' the min is 33 which is wrong.
i tried to write myself the iterations. i got little confused.
also if i check the max value instead of min its working fine with if.
Code:
#include <stdio.h>
int main(){
int number[] = {35,32,21,4,33,43,2};
int i, j , k ,min;
i= 0 ; j=6; k = 0; //j = the end of the array
//k = start of the array
for(; i<=j; i++){
while(number[k]>number[0+i]) //put 'if' is wrong.why?
{
k++;
}
}
min=number[k];
printf("min=%d",min);
return0;
}