有道编程 面试题 (1)有0,1,2到99这100个正整数,中间丢失了一个,剩余的99个数打乱顺序放在一个数组里, 问怎样找到丢失的那个数。
my solution is: add them and reduced by 10*9/2. like this:
int qu2[] = {7,6,4,9,1,3,2,8};
//find the missing one number
void amazon3(int u[], int n){
int t=0;
for(int i=0;i<n;i++){
t +=u[i];
}
printf("missing one is: %d\n", 10*9/2 - t);
}