A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C++ program to find the missing number in a given array of integers taken from the sequence 0, 1, 2, 3, ...,n
Q:

Write a C++ program to find the missing number in a given array of integers taken from the sequence 0, 1, 2, 3, ...,n

0

Write a C++ program to find the missing number in a given array of integers taken from the sequence 0, 1, 2, 3, ...,n

Sample Input: arr[10] = {10, 9, 4, 6, 3, 2, 5, 7, 1, 0 }
Sample Output: Missing number in the said array: 8
Sample Input: arr1[4] = {0, 3, 4, 2}
Sample Output: Missing number in the said array: 1

Sample Output:

Original array
0 1 7 5 2 3 6 4 9 10
Missing number in the said array:
8

Original array
2 4 3 0
Missing number in the said array:
1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

using namespace std;

int missingNumber(int nums[], int arr_size) {
        if (NULL == nums || arr_size == 0) {
            return 0;
        }
        int result = arr_size;
        for (int i = 0; i < arr_size; i++) {
            result ^= i;
            result ^= nums[i];
        }
        return result;
    }

int main() {
	int arr[10] = {10, 9, 4, 6, 3, 2, 5, 7, 1, 0 };
	int arr_size = sizeof(arr) / sizeof(arr[0]);
	cout << "Original array\n";
	for (int i = arr_size - 1; i >= 0; i--) 
    cout << arr[i] << " ";
    cout << "\nMissing number in the said array: ";
    cout << "\n" <<  missingNumber(arr, arr_size);
    
    int arr1[4] = {0, 3, 4, 2};
	arr_size = sizeof(arr1) / sizeof(arr1[0]);
	cout << "\n\nOriginal array\n";
	for (int i = arr_size - 1; i >= 0; i--) 
    cout << arr1[i] << " ";
    cout << "\nMissing number in the said array: ";
    cout << "\n" <<  missingNumber(arr1, arr_size);
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now