+ 1

Array

How we find the index of array?

3rd Feb 2025, 5:00 AM
Sankar Zaya
Sankar Zaya - avatar
5 Respostas
+ 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.
3rd Feb 2025, 7:31 AM
Lothar
Lothar - avatar
+ 3
BroFar it's tagged 'c'...🤣
3rd Feb 2025, 9:50 AM
Bob_Li
Bob_Li - avatar
+ 3
Guys sry I had an issue on my side ... can't explain but corrected .. Thanks 👍 for flagging Bob_Li Zvi
3rd Feb 2025, 2:48 PM
BroFar
BroFar - avatar
+ 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; }
3rd Feb 2025, 7:19 AM
BroFar
BroFar - avatar
+ 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.
3rd Feb 2025, 1:57 PM
Zvi
Zvi - avatar