Q:

Unpredictable result in counting pairs of integers

The task of the program is to count how many times there are two consecutive integers their value exceeds 40. So, the problem here is that the result of the program is way wrong.
To solve this problem, I tried το change some initial values and investigating the mechanism of the code, but I didn't notice any mistakes. The code is below.
#include <stdio.h>
int main() {

    int a,i,e=0;
    int A[31];
    for(i=0; i<=30; i++) {
        scanf("%d",&a);
        A[i]=a;
}
    if (A[i]>40 && A[i+1]>40) {
        e=e+1;
    }
    printf("%d",e); 

    return 0;
}

The expected result if we enter the integer 41 in all of 31 places of the matrix, the result should be 30, while the result there is always zero (0)
Thank you in advance for your help.

A:

"if statement" must be in loop.
And, Please aware the condition of 2nd loop what I set it as '< 30' instead of '<= 30' because your program want to compare the next variable together as "if (A[i] > 40 && A[i + 1] > 40)". 
#include <stdio.h>
int main()
{
        int a, i, e = 0;
        int A[31];
        for (i = 0; i <= 30; i++) {
            scanf("%d", &a);
            A[i] = a;
        }

        for (i = 0; i < 30; i++){
            if (A[i] > 40 && A[i + 1] > 40)
                e = e + 1;
        }
        printf("%d", e);

        return 0;
}

