user12980259
user12980259

Reputation:

How to find missing number between range of incremented numbers?

Good day foreveryone,

Let's assume I have range of numbers, say from 0 to 10. And the client removed one item from them. I need to know which mathematical formula should I know to find out the missing number. (Using C#). I guess there is a relation between sum and count for this group of numbers.

Upvotes: 0

Views: 795

Answers (2)

user12980259
user12980259

Reputation:

Input

1,2,3,5,6

Output
Missing Number : 4

Now to calculate missing number

Solution:
total numbers=5
sum of 6 numbers from 1 to 6 =

6*(6+1)/2;   
//Count(input)*(count(input)+1)/2
=21;     

sum of the Numbers in the sequence =17.

//sum(input) 
=17;

missing Number=sum of 6 numbers-sum of the Numbers in the sequence

= 21-17 = 4

Upvotes: 0

Ammo Goettsch
Ammo Goettsch

Reputation: 870

I think your teacher expects you to know the Little Gauss formula.

Don’t want to spoil all your homework, so just sum the numbers you have left and check what you are missing since you know the total from this formula.

History: http://mathcentral.uregina.ca/qq/database/qq.02.06/jo1.html

Upvotes: 2

Related Questions