answersLogoWhite

0


Best Answer

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;

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: 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?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is 2.5 an integer?

No, but 2 and 3 are.No because integers are whole numbers


What is the difference between varchar and int?

The former is for strings, the later is for numbers (integers).


Code for sum of first natural numbers in python language?

For the first 5 natural numbers (integers):x = 1 + 2 + 3 + 4 + 5print xFor 'n' amount of natural numbers (Python v2 example)n = int(raw_input('Enter max integer: '))count = 0sumn = 0while count < n:sumn = sumn + 1count = count + 1print sumn


Rules for function overloading?

It's a way by which you use define the same function for different input types. For example, think about the the operator "+" which in java works for adding integers, floating point numbers and even string concatenation. The way such functionality is achieved is by overloading.


What is a type as a term that relates to programming?

Computer programs store and handle data; this data can come in different types. For example, some languages define numeric types, which can further be subdivided into integers and floating-point numbers (i.e. numbers that don't accept decimals, and numbers that do), dates, boolean or logical data (can only contain the values "true" or "false"), strings (to store text or other symbols), and others.Classes are a way to define additional (user-defined) types. Such user-defined types usually consist of several other data types. For example, you might decide that to store information about a point in space, you need three coordinates - 3 floating-point numbers, one for each of the 3 coordinates.

Related questions

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.


What is an example of subtraction of integers?

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


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.


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 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.


Are some integers not rational numbers?

All integers are rational numbers. There are integers with an i behind them that are imaginary numbers. They are not real numbers but they are rational. The square root of 2 is irrational. It is real but irrational.


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.


Whole numbers and their opposites are called what?

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


What are the numbers 2 5 8 11 an example of?

Integers.


What are some example of real numbers in addition?

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


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.


When are rational numbers not natural?

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


Can non-integers be negative numbers?

Yes. Example: -403.27 you bet!