Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Find the Missing Number

#include <bits/stdc++.h>
using namespace std;
 
// Function to get the missing number
int getMissingNo(int a[], int n)
{
 
    int total = (n + 1) * (n + 2) / 2;
    for (int i = 0; i < n; i++)
        total -= a[i];
    return total;
}
 
// Driver Code
int main()
{
    int arr[] = { 1, 2, 4, 5, 6 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int miss = getMissingNo(arr, n);
    cout << miss;
}
Comment

missing number

numbers = input("Enter your numbers with ','separated form : ")
int_array = list(map(int,numbers.split(",")))
Sum = 0
for i in range(len(int_array)):
    Sum = Sum+int_array[i]
n = len(int_array) +1
missing = (((n+1) * (n))/2) -Sum 
print(missing)
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

find the missing number

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,15]);
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ add to array 
Cpp :: stoi() c++ 
Cpp :: How to create files in C++ 
Cpp :: vector find 
Cpp :: c++ pass array to a function 
Cpp :: abs in cpp 
Cpp :: c++ min int 
Cpp :: 3d vector c++ resize 
Cpp :: unique_ptr syntax 
Cpp :: priority queue smallest first 
Cpp :: c++ back() 
Cpp :: cpp float 
Cpp :: gettimeofday header file 
Cpp :: Find the biggest element in the array 
Cpp :: intersection.cpp 
Cpp :: operand-- c++ 
Cpp :: array length c++ 
Cpp :: constructor in cpp 
Cpp :: input full line as input in cpp 
Cpp :: Give an algorithm for finding the ith-to-last node in a singly linked list in which the last node is indicated by a null next reference. 
Cpp :: c++ class template 
Cpp :: how to convert string to int in c++ 
Cpp :: heap buffer overflow in c 
Cpp :: exponent power of x using c c++ 
Cpp :: put text on oled 
Cpp :: get std string from file 
Cpp :: array copx c++ 
Cpp :: string in c++ 
Cpp :: c++ pass ofstream as argument 
Cpp :: flag of georgia 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =