C Program to Find Missing number in Array

Write a c program to find missing number in array. Given an array of numbers from 1 to 100. The array is sorted. One number is missing from an array. You have to find the missing number from an array. This question is generally asked in technical interviews. Also there is no duplicates in an array.

There are multiple approaches to solve this problem. Here i am going to explain two approaches to solve this problem and both the solution take O(n) time complexity.

Programming questions on array

How to Find Missing Number in Array


Subscribe Our Tutorials

Get Latest Updates on Facebook

1. As per problem statement we have an array of 1 to 100 numbers and there is no duplicate number in an array. One number is missing and we have to find it.

Let’s first calculate the sum of 1 to 100 numbers. We can calculate easily by using sum of the series formula.

2. In next step, add all the numbers of an array.

Now, we have the sum of 100 numbers and sum of all the numbers in an array.

If we subtract the sum of 100 numbers to the sum of all the numbers in an array we get the missing number.

Time complexity of this problem is O(n).

C Program to Find Missing Number in Array

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.