Skip to content

Instantly share code, notes, and snippets.

@thequbit
Created November 21, 2013 19:14
Show Gist options
  • Save thequbit/7587747 to your computer and use it in GitHub Desktop.
Save thequbit/7587747 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define LENGTH 99
#define MISSING_NUMBER 47
int main()
{
// vars
int numbers[LENGTH];
int missingnumber = -1;
int i;
// create array-o-numbers
for (i=0; i<MISSING_NUMBER; i++)
numbers[i]=i;
for (i=MISSING_NUMBER+1; i<LENGTH; i++)
numbers[i]=i;
// find missing number
i = 0;
while(i < LENGTH-1)
{
if( numbers[i+1]-numbers[i] > 1)
{
missingnumber = i;
break;
}
i++;
}
// test
if( missingnumber == MISSING_NUMBER )
printf("Missing number found successfully!\n");
else
printf("ERROR! Expecting: %i, Found: %i\n",MISSING_NUMBER,missingnumber);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment