Problem 1: Using appropriate algorithm

Consider the following checkSum() method where N numbers are saved in an array (as sorted in as-cending order). In the main() function, the user will input a number. The checkSum() method will find out whether the sum of any two numbers in the array is equal to the given number by the user. You need to solve the problem with minimum time complexity (low complexity will lead to higher marks!).
1 #include <iostream> 2 using namespace std ; 3 void checkSum ( int num) 4 { 5     int N = 1 0; 6     int array[N]; 7     bool result = false; 8 9     for ( int i = 0 ; i < N; i++) 10         array [ i ] = i ; 11 12     // YOUR CODE HERE (TO FIND THE RESULT) 13 14     if ( result ) 15         cout << ”Present ” ; 16     else 17         cout <<”Absent” ; 18 } 19 int main ( ) 20 { 21     int number ; 22     cout << ”Enter a Number : ” ; 23     cin >> number ; 24     checkSum ( number ) ; 25 }

Code:

#include<iostream>
using namespace std;

void checkSum(int num)
{
    int N = 10;
    int array[N];
    bool result = false;

    for (int i = 0i < Ni++)
    {
        array[i] = i;
    }

    for (int i = 0i < Ni++)
    {
        for(int j = 0j < N && (j != i); j++)
        {
            if (array[i] + array[j] == num)
                result = true;           
        }
    }
    // TIME COMPLEXITY: O(n^2)

    if (result)
        cout << "Present";
    else
        cout << "Absent";
}

int main()
{
    int number;
    cout << "Enter a Number: ";
    cin >> number;
    checkSum(number);
}