c++ take n number from the user and store them in array and get the max, min number of them and also find the average/summation of these numbers

#include <iostream>

int main() {
    int n;

    // Input the number of elements
    std::cout << "Enter the number of elements: ";
    std::cin >> n;

    // Declare an array of size n
    int arr[n];

    // Input n numbers and store them in the array
    for (int i = 0; i < n; ++i) {
        std::cout << "Enter element " << i + 1 << ": ";
        std::cin >> arr[i];
    }

    // Find the maximum and minimum numbers
    int maxNum = arr[0];
    int minNum = arr[0];

    for (int i = 1; i < n; ++i) {
        if (arr[i] > maxNum) {
            maxNum = arr[i];
        }

        if (arr[i] < minNum) {
            minNum = arr[i];
        }
    }

    // Calculate the sum and average of the numbers
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += arr[i];
    }

    double average = static_cast<double>(sum) / n;

    // Output the results
    std::cout << "Maximum number: " << maxNum << std::endl;
    std::cout << "Minimum number: " << minNum << std::endl;
    std::cout << "Sum: " << sum << std::endl;
    std::cout << "Average: " << average << std::endl;

    return 0;
}