So I've written this to print "Yes when the code is in ascending order and "No" when it is not. But if I start with equal values in the beginning, the program prints an incorrect result. I don't understand why the if statement runs even if the condition isn't met.
#include <iostream>
using namespace std;
int main()
{
    int N, i;
    scanf("%d", &N);
    int arr[N];
    for(i = 1; i <= N; i++)
    {
        scanf("%d", &arr[i - 1]);
    }
    for(i = 1; i <= N; i++)
    {
        if(arr[i - 1] > arr[i])
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}
 
    