How can I find a missing number on integer array of 1 to 100 elements? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I find a missing number on integer array of 1 to 100 elements?

16th Jun 2018, 5:36 AM
Nsimbe Kevin
Nsimbe Kevin - avatar
2 Answers
+ 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
16th Jun 2018, 5:54 AM
AliR૯za
AliR૯za - avatar
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
16th Jun 2018, 1:23 PM
hinanawi
hinanawi - avatar