A
A
Andrey Rudenko2020-11-08 19:36:29
C++ / C#
Andrey Rudenko, 2020-11-08 19:36:29

How to display paired numbers in si?

Good evening! Faced such a problem, I don’t really understand how to display paired numbers, please help me, what am I doing wrong?
The code:

#include <stdio.h>
#include <stdlib.h>
#define N 16
int main() {
    int a[N], A, i;
    int count=0;
    printf("Input A="); scanf ("%i", &A);
    printf("Выходные данные ");
    for (i=0; i<N; i++) {
        a[i] = 5,5,6,6,10,22,22,11,11,53,-3,-3,7,9,1,41;
        printf("%d ", a[i]);
    }
    printf("\nОдинаковые числа ");
    for (i=0; i<N; i++) {
        if(a[i] % 2 == 0 && a[i] > A)
        {
            count++;
            printf("%i ", a[i]);
        }
    }
    printf("\nКоличество парных чисел = %d", count);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-11-08
@FlapsBat

Sort the array. Use the standard qsort function .
Then iterate over the array. Output the current number if it is equal to the previous one and not equal to the next one, or comes last: An inequality check is needed to output only one of many copies of a number.
if (a[i] == a[i-1] && (i+1== n || a[i+1] != a[i])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question