Analysis of the Algorithm
We sequentially read and process numbers. We count the required number of numbers in the variable cnt
. We calculate the sought sum in sum
.
Implementation of the Algorithm
We read the number of numbers .
scanf("%d", &n);
We count the number of required numbers and their sum in the variables cnt
and sum
.
cnt = sum = 0;
We sequentially read numbers.
for (i = 0; i < n; i++) { scanf("%d", &a); if (a > 0 && a % 6 == 0) { cnt++; sum += a; } }
We output the answer.
printf("%d %d\n", cnt, sum);