Find the Missing Number

Find the Missing Number
1. Get the sum of numbers
       total = n*(n+1)/2
2  Subtract all the numbers from sum and
   you will get the missing number.


int MissingNo(int a[],int n)
    int i,sum;
    sum=(n+1)*(n+2)/2; //n*(n+1)/ but no. is missing so (a,7) in array 7 to find sum of 8 element sum=(n+1)*(n+2)/2 including missing number
    return sum;

int main()
    int a[] = {1,2,4,5,6,7,8};
    int Number;


    printf("Missing No. is:%d\n",Number);
Copyright © C Program | Java | OpenGL Programming | Hadoop at Computaholics