It is required to write a program that displays the product of two-digit numbers in an array that are not a multiple of seven. I wrote on the following

#include <stdio.h> #define N 5 void main(void) { long A[N]; long j, i, p; for (i = 0; i < N; i++) { scanf("%ld", &A[i]); } p = 1; for (i = 0; i < N; i++) { if (A[i] >= 10 && A[i] <= 99 && A[i] % 7 != 0) { j = A[i]; p = p * j; } } printf("%ld", p); } 

But this only displays the last element of the array. Help catch the error.

  • Paste the code right here, some lazy to follow the link. - Vladimir Gordeev
  • one
    Why did you correct the code for the correct one? - dzhioev

1 answer 1

First, instead of <= 10, it should be> = 10. Secondly, instead of the bitwise operator &, you must use the logical operator &&. In this case, it does not affect the result, but in other cases problems may arise.