+ 1
How can I find a missing number on integer array of 1 to 100 elements?
2 Réponses
+ 12
in c++ :
for(int a:arr)
if (a==number) cout<<a;
or:
for(int x=0;x<100;x++)
if (arr[x]==number) cout<<x;
----------------------------
in second one it show aray's index
0
if you know the array should contain numbers from 1 to 100, then you can sort it and iterate through the values. when you find a value which isn't equal to its' index + 1, the missing one is on that position