Hello there.Code:#include <stdio.h> int main(void){ int i,pos,num,minimum; for(i=1;i<=5;i++){ printf("Input an integer:"); scanf("%d",&num); printf("\n"); if(num<0){ minimum=num; pos=i; } } printf("The smallest negative integer is %d and its position is %d",minimum,pos); printf("Have a good one\n\n"); system("pause"); }
So, this small little program is supposed to get 500 numbers from input, and then determine which one is the smallest negative. For instance, between 4 -2 -4 10 -23, the smallest negative number would be -2.
However it does not seem to work because it just prints out the last negative integer which went into the program.
Could someone enlighten me?