program to find third smallest number c++

#include<iostream>
#includeclimits>
using namespace std;

int thirdSmallest(int arr[], int size) {
    if (size < 3) {
        cout << "Array size is less than 3." << endl;
        return INT_MIN;
    }

    int first, second, third;
    first = second = third = INT_MAX;

    for (int i = 0; i < size; i++) {
        if (arr[i] < first) {
            third = second;
            second = first;
            first = arr[i];
        } else if (arr[i] < second && arr[i] != first) {
            third = second;
            second = arr[i];
        } else if (arr[i] < third && arr[i] != second && arr[i] != first) {
            third = arr[i];
        }
    }

    return third;
}

int main() {
    int size;
    cout << "Enter the size of the array: ";
    cin >> size;

    int arr[size];
    cout << "Enter the elements of the array:" << endl;
    for (int i = 0; i < size; i++) {
        cin >> arr[i];
    }

    int result = thirdSmallest(arr, size);
    if (result != INT_MIN) {
        cout << "The third smallest number in the array is: " << result << endl;
    }

    return 0;
}