Created
November 21, 2013 19:14
-
-
Save thequbit/7587747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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