set the counter to 0, and increment it every time you find 1. When the array is fully analyzed, you will know which one was the last.
int counter = 0; int lastone = -1; for(i = 0; i < 5; i++) { if(array[i]==1) { counter++; lastone = i; printf("found one\n"); } } if(lastone!=-1) printf(" %d one is the last one %d", counter, lastone);
user2560622
source share