+ 1
Array
How we find the index of array?
5 ответов
+ 4
Sankar Zaya ,
it would be helpful if you could give some more details. please give a brief description what you are going to achieve with your code.
if you have done a try so far, please post it here.
+ 3
BroFar it's tagged 'c'...🤣
+ 3
Guys sry I had an issue on my side ... can't explain but corrected .. Thanks 👍 for flagging
Bob_Li
Zvi
+ 2
Sankar Zaya something like this ....
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int size = sizeof(arr) / sizeof(arr[0]);
int target = 30;
for (int j = 0; j < size; j++){
if (arr[j] == target){
printf("%d ",j); // index of target
}
}
return 0;
}
+ 2
BroFar why would you do it that way over
let arr=[10,20,30,40];
let index= arr.indexOf(30);
console.log(index)
Or does your way also work for c while mine in only Javascript? Because what you did doesn’t look to me like c, although I really don’t know much about c, but it does look like javascript.