Answer the question
In order to leave comments, you need to log in
How to compare each element of an array with all other elements?
According to the conditions of the problem, an array is given, I choose the size myself, I took 10. The goal is to display the number of repeated array elements in the definition area from m1 to m2 (values are set by the user), and if there are none, display a message.
I don’t quite understand how I can write a comparison of the current element of the array in the for loop with all its other elements, or can I even do without a loop here?
Here's what's recorded so far:
#include <stdio.h>
#include <math.h>
int main () {
int m1, m2;
const int N=10;
int arr [N];
int i;
int count=0;
do {
printf ("Input m1, m2");
scanf ("%f%f", &m1, &m2);
}
while (m1>=m2);
for (i=m1; i<=m2; i++){
printf ("Element with index %f: ", i)
scanf ("%f", &arr[i]);
}
}
Answer the question
In order to leave comments, you need to log in
I don’t quite understand how I can compare the current element of the array in the for loop with all its other elements
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question