Skip to content

Instantly share code, notes, and snippets.

@asa55
Created April 3, 2020 22:19
Show Gist options
  • Save asa55/50d3fd03aaff19ba47db40708fb6149e to your computer and use it in GitHub Desktop.
Save asa55/50d3fd03aaff19ba47db40708fb6149e to your computer and use it in GitHub Desktop.
// How do you find the missing number in a given integer array of 1 to 100?
#include <iostream>
#include <algorithm>
int arr[100];
int main()
{
for( int i = 0; i < 100; ++i )
arr[i] = i + 1;
arr[49] = 0;
//std::for_each(&arr[0], &arr[99], [](int el){std::cout << el << std::endl;});
for (int _el : arr)
std::cout << _el << std::endl;
int* missing_num_location = std::find(&arr[0], &arr[99], 0);
std::cout << std::endl << missing_num_location - &arr[0] <<std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment