vendredi 28 septembre 2018

Searching for values in array

i'm new to coding and have been introduced to C language. I need help understanding a specific concept.

I want to know how I can search for a specific number(e.g. 4) in a array(e.g. {1 2 4 5 6 4 6}). How ever I want to print out the index of the last occurrence of 4. How can I do this?

I have managed to so far do this...What u don't understand is how to show the ''last occurrence of a given number''

#include <stdio.h>
LastIndexOf(int search, int values[], int numValues){
int i;
int display;
for(i=0;i<numValues;i++){
if(values[i] == search){
display = i
}
}
}

any help would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire