# Find missing number in range

Here given code implementation process.

``````// C program for
// Find missing number in range
#include <stdio.h>

void findMissingNo(int arr[], int n)
{
if (n <= 1)
{
return;
}
int xorValue = 0;
int minValue = arr[0];
// Find min value
for (int i = 1; i < n; ++i)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
}
for (int i = 0; i < n; ++i)
{
xorValue = xorValue ^ minValue ^ arr[i];
// Increase the min value
minValue++;
}
int result = minValue ^ xorValue;
// Display calculated result
printf("\n %d", result);
}
int main(int argc, char
const *argv[])
{
int a[] = {
3 , 4 , 5 , 7 , 8 , 9 , 10
};
int b[] = {
13, 7, 6, 10, 9, 5, 11, 12
};
int n = sizeof(a) / sizeof(a[0]);
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
findMissingNo(a, n);
// Example 2
n = sizeof(b) / sizeof(b[0]);
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
findMissingNo(b, n);
return 0;
}``````

#### Output

`````` 6
8``````
``````/*
Java program
Find missing number in range
*/
public class MissingValue
{
public void findMissingNo(int[] arr, int n)
{
if (n <= 1)
{
return;
}
int xorValue = 0;
int minValue = arr[0];
// Find min value
for (int i = 1; i < n; ++i)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
}
for (int i = 0; i < n; ++i)
{
xorValue = xorValue ^ minValue ^ arr[i];
// Increase the min value
minValue++;
}
int result = minValue ^ xorValue;
// Display calculated result
System.out.print("\n " + result);
}
public static void main(String[] args)
{
int[] a = {
3 , 4 , 5 , 7 , 8 , 9 , 10
};
int[] b = {
13 , 7 , 6 , 10 , 9 , 5 , 11 , 12
};
int n = a.length;
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = b.length;
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}
}``````

#### Output

`````` 6
8``````
``````// Include header file
#include <iostream>
using namespace std;
/*
C++ program
Find missing number in range
*/
class MissingValue
{
public: void findMissingNo(int arr[], int n)
{
if (n <= 1)
{
return;
}
int xorValue = 0;
int minValue = arr[0];
// Find min value
for (int i = 1; i < n; ++i)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
}
for (int i = 0; i < n; ++i)
{
xorValue = xorValue ^ minValue ^ arr[i];
// Increase the min value
minValue++;
}
int result = minValue ^ xorValue;
// Display calculated result
cout << "\n " << result;
}
};
int main()
{
int a[] = {
3 , 4 , 5 , 7 , 8 , 9 , 10
};
int b[] = {
13 , 7 , 6 , 10 , 9 , 5 , 11 , 12
};
int n = sizeof(a) / sizeof(a[0]);
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = sizeof(b) / sizeof(b[0]);
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
return 0;
}``````

#### Output

`````` 6
8``````
``````// Include namespace system
using System;
/*
Csharp program
Find missing number in range
*/
public class MissingValue
{
public void findMissingNo(int[] arr, int n)
{
if (n <= 1)
{
return;
}
int xorValue = 0;
int minValue = arr[0];
// Find min value
for (int i = 1; i < n; ++i)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
}
for (int i = 0; i < n; ++i)
{
xorValue = xorValue ^ minValue ^ arr[i];
// Increase the min value
minValue++;
}
int result = minValue ^ xorValue;
// Display calculated result
Console.Write("\n " + result);
}
public static void Main(String[] args)
{
int[] a = {
3 , 4 , 5 , 7 , 8 , 9 , 10
};
int[] b = {
13 , 7 , 6 , 10 , 9 , 5 , 11 , 12
};
int n = a.Length;
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = b.Length;
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}
}``````

#### Output

`````` 6
8``````
``````package main
import "fmt"
/*
Go program
Find missing number in range
*/
type MissingValue struct {}
func getMissingValue() * MissingValue {
var me *MissingValue = &MissingValue {}
return me
}
func(this MissingValue) findMissingNo(arr[] int, n int) {
if n <= 1 {
return
}
var xorValue int = 0
var minValue int = arr[0]
// Find min value
for i := 1 ; i < n ; i++ {
if minValue > arr[i] {
minValue = arr[i]
}
}
for i := 0 ; i < n ; i++ {
xorValue = xorValue ^ minValue ^ arr[i]
// Increase the min value
minValue++
}
var result int = minValue ^ xorValue
// Display calculated result
fmt.Print("\n ", result)
}
func main() {
var task * MissingValue = getMissingValue()
var a = [] int {
3,
4,
5,
7,
8,
9,
10,
}
var b = [] int {
13,
7,
6,
10,
9,
5,
11,
12,
}
var n int = len(a)
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = len(b)
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}``````

#### Output

`````` 6
8``````
``````<?php
/*
Php program
Find missing number in range
*/
class MissingValue
{
public	function findMissingNo(\$arr, \$n)
{
if (\$n <= 1)
{
return;
}
\$xorValue = 0;
\$minValue = \$arr[0];
// Find min value
for (\$i = 1; \$i < \$n; ++\$i)
{
if (\$minValue > \$arr[\$i])
{
\$minValue = \$arr[\$i];
}
}
for (\$i = 0; \$i < \$n; ++\$i)
{
\$xorValue = \$xorValue ^ \$minValue ^ \$arr[\$i];
// Increase the min value
\$minValue++;
}
\$result = \$minValue ^ \$xorValue;
// Display calculated result
echo("\n ".\$result);
}
}

function main()
{
\$a = array(3, 4, 5, 7, 8, 9, 10);
\$b = array(13, 7, 6, 10, 9, 5, 11, 12);
\$n = count(\$a);
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
\$n = count(\$b);
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}
main();``````

#### Output

`````` 6
8``````
``````/*
Node JS program
Find missing number in range
*/
class MissingValue
{
findMissingNo(arr, n)
{
if (n <= 1)
{
return;
}
var xorValue = 0;
var minValue = arr[0];
// Find min value
for (var i = 1; i < n; ++i)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
}
for (var i = 0; i < n; ++i)
{
xorValue = xorValue ^ minValue ^ arr[i];
// Increase the min value
minValue++;
}
var result = minValue ^ xorValue;
// Display calculated result
process.stdout.write("\n " + result);
}
}

function main()
{
var a = [3, 4, 5, 7, 8, 9, 10];
var b = [13, 7, 6, 10, 9, 5, 11, 12];
var n = a.length;
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = b.length;
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}
main();``````

#### Output

`````` 6
8``````
``````#    Python 3 program
#    Find missing number in range
class MissingValue :
def findMissingNo(self, arr, n) :
if (n <= 1) :
return

xorValue = 0
minValue = arr[0]
i = 1
#  Find min value
while (i < n) :
if (minValue > arr[i]) :
minValue = arr[i]

i += 1

i = 0
while (i < n) :
xorValue = xorValue ^ minValue ^ arr[i]
#  Increase the min value
minValue += 1
i += 1

result = minValue ^ xorValue
#  Display calculated result
print("\n ", result, end = "")

def main() :
a = [3, 4, 5, 7, 8, 9, 10]
b = [13, 7, 6, 10, 9, 5, 11, 12]
n = len(a)
#  Example 1
#  a [] = [3, 4, 5, 7, 8, 9, 10]
#  Example 2
n = len(b)
#  b [] = [13, 7, 6, 10, 9, 5, 11, 12]

if __name__ == "__main__": main()``````

#### Output

``````  6
8``````
``````#    Ruby program
#    Find missing number in range
class MissingValue
def findMissingNo(arr, n)
if (n <= 1)
return
end

xorValue = 0
minValue = arr[0]
i = 1
#  Find min value
while (i < n)
if (minValue > arr[i])
minValue = arr[i]
end

i += 1
end

i = 0
while (i < n)
xorValue = xorValue ^ minValue ^ arr[i]
#  Increase the min value
minValue += 1
i += 1
end

result = minValue ^ xorValue
#  Display calculated result
print("\n ", result)
end

end

def main()
a = [3, 4, 5, 7, 8, 9, 10]
b = [13, 7, 6, 10, 9, 5, 11, 12]
n = a.length
#  Example 1
#  a [] = [3, 4, 5, 7, 8, 9, 10]
#  Example 2
n = b.length
#  b [] = [13, 7, 6, 10, 9, 5, 11, 12]
end

main()``````

#### Output

`````` 6
8``````
``````/*
Scala program
Find missing number in range
*/
class MissingValue()
{
def findMissingNo(arr: Array[Int], n: Int): Unit = {
if (n <= 1)
{
return;
}
var xorValue: Int = 0;
var minValue: Int = arr(0);
var i: Int = 1;
// Find min value
while (i < n)
{
if (minValue > arr(i))
{
minValue = arr(i);
}
i += 1;
}
i = 0;
while (i < n)
{
xorValue = xorValue ^ minValue ^ arr(i);
// Increase the min value
minValue += 1;
i += 1;
}
var result: Int = minValue ^ xorValue;
// Display calculated result
print("\n " + result);
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: MissingValue = new MissingValue();
var a: Array[Int] = Array(3, 4, 5, 7, 8, 9, 10);
var b: Array[Int] = Array(13, 7, 6, 10, 9, 5, 11, 12);
var n: Int = a.length;
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = b.length;
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}
}``````

#### Output

`````` 6
8``````
``````import Foundation;
/*
Swift 4 program
Find missing number in range
*/
class MissingValue
{
func findMissingNo(_ arr: [Int], _ n: Int)
{
if (n <= 1)
{
return;
}
var xorValue: Int = 0;
var minValue: Int = arr[0];
var i: Int = 1;
// Find min value
while (i < n)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
i += 1;
}
i = 0;
while (i < n)
{
xorValue = xorValue ^ minValue ^ arr[i];
// Increase the min value
minValue += 1;
i += 1;
}
let result: Int = minValue ^ xorValue;
// Display calculated result
print("\n ", result, terminator: "");
}
}
func main()
{
let a: [Int] = [3, 4, 5, 7, 8, 9, 10];
let b: [Int] = [13, 7, 6, 10, 9, 5, 11, 12];
var n: Int = a.count;
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = b.count;
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}
main();``````

#### Output

``````  6
8``````
``````/*
Kotlin program
Find missing number in range
*/
class MissingValue
{
fun findMissingNo(arr: Array < Int > , n: Int): Unit
{
if (n <= 1)
{
return;
}
var xorValue: Int = 0;
var minValue: Int = arr[0];
var i: Int = 1;
// Find min value
while (i < n)
{
if (minValue > arr[i])
{
minValue = arr[i];
}
i += 1;
}
i = 0;
while (i < n)
{
xorValue = xorValue xor minValue xor arr[i];
// Increase the min value
minValue += 1;
i += 1;
}
val result: Int = minValue xor xorValue;
// Display calculated result
print("\n " + result);
}
}
fun main(args: Array < String > ): Unit
{
val a: Array < Int > = arrayOf(3, 4, 5, 7, 8, 9, 10);
val b: Array < Int > = arrayOf(13, 7, 6, 10, 9, 5, 11, 12);
var n: Int = a.count();
// Example 1
// a [] = [3, 4, 5, 7, 8, 9, 10]
// Example 2
n = b.count();
// b [] = [13, 7, 6, 10, 9, 5, 11, 12]
}``````

#### Output

`````` 6
8``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.