I just learned how arrays works and I'm trying to find the maximum element in an array, but I can't get all the values I want into the array. I tried this way:
int x[10];
for (i = 1; i <= 10; i++)
{
printf("please enter a number: ");
scanf_s("%d", x[i]);
}
Below is the whole program
#include <stdio.h>
int main(void)
{
int i = 1;
int max, min;
int x[10];
for (i = 1; i <= 10; i++)
{
printf("please enter a number: ");
scanf_s("%d", x[i]);
}
for (i = 1; i <= 10; i+2)
{
if (x[i] > x[i + 1])
max = x[i];
else
max = x[i + 1];
}
for (i = 1; i <= 10; i + 2)
{
if (x[i] < x[i + 1])
min = x[i];
else
min = x[i + 1];
}
printf("max = %d , min = %d", max, min);
return 0;
}
`code ticks`for multi-line code, but to use the {} button (orCtrl+K) instead.