Computer Programming

Math and Arithmetic

Statistics

Algebra

# The integers from 1 to n are stored in an array in random fashion. One of the numbers is missing. What is an example of a program that will find the missing number?

567

## Answer

###### Wiki User

###### 05/18/2008

1. Determine the sum of 1..n = (n(n+1))/2 2. Subtract all the elements in the given array (n-1 elements) from the expected sum. 3. The missing number is the value remaining. /* Implementation in "C" */

int MissingNumber(int values[], int n)

{

int total = (n * (n+1))/2;

while (n>1)

{

total -= values[n-2];

n--;

}

return total;

}

## Related Questions

###### Asked in Numbers

### How are integers and national numbers the same?

There are no national numbers.
Some integers are natural numbers but not all - for example,
negative integers.
...

Read More

###### Asked in Numbers

### Are some rational numbers are integers?

Since all integers are rational numbers (but not all rational
numbers are integers), the certainly some of the rational numbers
are integers.
For example, 1, 2, and 3 are rational numbers. They are also
integers.
...

Read More

###### Asked in Math and Arithmetic

### How can you classify different numbers?

Obviously, there are an infinite number of ways you can classify
numbers.
For example, you can classify positive and negative numbers;
integers and non-integers; rational and irratinoal numbers; real
numbers and complex numbers.
Obviously, there are an infinite number of ways you can classify
numbers.
For example, you can classify positive and negative numbers;
integers and non-integers; rational and irratinoal numbers; real
numbers and complex numbers.
Obviously, there are an infinite number of ways you can classify
numbers.
For example, you can classify positive and negative numbers;
integers...

Read More

###### Asked in Math and Arithmetic

### What is an example of subtraction of integers?

Integers are whole numbers as for example 28 minus 17 = 11

Read More

###### Asked in Numbers

### Are all real numbers integers?

No, all integers are real numbers, but not all real numbers are
integers. For example, 1.25 is a real number and a
non-integer.
No.
...

Read More

###### Asked in Math and Arithmetic

### What are the example of whole numbers?

Whole numbers are integers that do not include decimals or
fractions as for example the whole numbers in the number line
...

Read More

###### Asked in Math and Arithmetic

### What is the missing numbers in this pattern 65 56 38?

All of the integers from 64 down to 57, and from 55 down to 39,
are missing.
...

Read More

###### Asked in Math and Arithmetic, Numbers

### What are whole numbers and their opposites called?

Whole numbers are called integers.
There are positive integers, for example, 3, and its opposite, a
negative integer, -3.
...

Read More

###### Asked in Math and Arithmetic, Algebra, Numbers

### What are some example of real numbers in addition?

Since integers are also real numbers, 2 + 3 = 5 is an
example.

Read More

###### Asked in Numbers

### Is the complement of the set of odd integers is the set of even integers?

It is if we only consider integers. If we consider all real
numbers, for example, it would not be.
...

Read More

###### Asked in Jobs & Education, Math and Arithmetic, Math History, Numbers

### How are integers different from whole numbers?

Whole numbers are integers. Integers are whole numbers.

Read More

###### Asked in Numbers

### When are rational numbers not natural?

Most of the time. For example, when they are negative
integers.

Read More

###### Asked in Numbers

### Are Some real numbers integers?

All integers are real numbers, but not all real numbers are
integers.

Read More

###### Asked in Math and Arithmetic, Numbers

### Are some whole numbers are not integers?

No. All whole numbers are integers and all integers are whole
numbers.

Read More

###### Asked in Math and Arithmetic

### How often are whole numbers integers?

Always.
By definition the Integers are the whole numbers; and the whole
numbers are the integers.
...

Read More

###### Asked in Numbers

### How do you compare integers with positive numbers?

Some integers are positive numbers.
Some integers are not positive numbers.
Some positive numbers are integers.
Some positive numbers are not integers.
They are two sets whose intersection is the set of counting
numbers.
...

Read More

###### Asked in Math and Arithmetic, Numbers

### How are the integers and rational number different?

Integers or whole numbers are rational numbers because they can
be expressed as fractions as for example 6 as a fraction is 6/1 but
irrational numbers can't be expressed as fractions.
...

Read More

###### Asked in Math and Arithmetic, Animal Life

### What does integers mean?

Integers are whole numbers with no fractional part, for example:
24, 3, 0, -5, 376 and 12345
...

Read More

###### Asked in Math and Arithmetic

### What does the word number integers mean?

Integers are whole numbers with no fractional part, for example:
24, 3, 1, 0, -5, 376 and 12345 are all integers. As you can see,
the set of integers includes zero as well as positive and negative
numbers.
...

Read More

###### Asked in Math and Arithmetic

### Can non-integers be negative numbers?

Yes. Example: -403.27
you bet!

Read More

###### Asked in Numbers

### Can you give an example of an integer that is not rational why or why not?

No, all integers are rational, whole numbers.

Read More

###### Asked in Numbers

### What are the rational numbers?

Informally, the set of fractions. The set of all numbers that
can be expressed as a fraction, with integers in the numerator and
denominator, for example 1/3, 5/3, -3/5, 4/1. The last example
shows that integers are also rational numbers.
...

Read More

###### Asked in Math and Arithmetic, Algebra, Numbers , Percentages, Fractions, and Decimal Values

### Can a decimal be an integer?

Yes.
For example 2.0 IS an integer, but note that most decimals are
not integers, eg 2.56 is not an integer.
Not normally because integers are whole numbers
...

Read More

###### Asked in Numbers

### Which of the following sets of numbers contains multiplicative inverses for all its elements Positive Integers Integers Rational Numbers Real Numbers?

Rational numbers and Real Numbers. The multiplicative inverses
of integers are not integers.
...

Read More

###### Asked in Numbers

### Are integers always positive numbers?

No. you could have, for example, -4 or 4 (or any other minus or
positive number).
Both are integers.
...

Read More