Kodewick
Start learning →
Basic←→0 / 70

Find my cat

#029BasicArraysLoops4 min

At the cat hotel, each cage has the cat's tag number, in order in the array tags. Write find_cat(tags, n, tag) to return the position (counting from 0) of the cat with number tag; if it appears twice, the first one; if it is not there, return -1.

Examples
find_cat({12, 40, 7}, 3, 40)→1
find_cat({12, 40, 7}, 3, 99)→-1
The functionint find_cat(int tags[], int n, int tag)
main.c
int find_cat(int tags[], int n, int tag) {
    for (int i = 0; i < n; i++) {
        // your code here: if the number matches, return i
    }
    return -1;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.