
Originally Posted by
emikash
Hello. I'm new to C programming and attending a web course. We learned about arrays but I still struggle to understand how to compare values in an array. Say I have
and I want to compare index 0 with index 1,2,3,4 not by typing
and
but
Code:
array[k] with array[?]
.
Thank you in advance, Mike
Code:
int main(void)
{
int array[5] = {2, 4, 6, 1, 5};
int j, k;
for (j =0; j < 5; j++)
for (k = 0; k < 5; k++)
{
char compare;
if (array[j] < array[k])
compare = '<';
else if (array[j] > array[k])
compare = '>';
else
compare = '=';
printf(array[%d] %c array[%d]\n", j, compare, k);
}
}