smallest value error

i cant get the smallest value in this code. please help!


// Find maximum and minimum element in an array.

#include<stdio.h>

int

main ()

{

int i;

int a[10];

int max = a[0];

int min = a[0];

for(i=0;i<10;i++)
scanf("%d", &a[i]);


for (i = 0; i < 10; i++)

{

if (a[i] > max)

{

max = a[i];

}

else if (a[i] < min)

{

min = a[i];
}

}
printf ("Maximum element in an array : %d\n", max);

printf ("Minimum element in an array : %d\n", min);



return 0;

}
I don't think it's a good idea initializing min and max before the array actually contains meaningful values.
thankyou Athar! :)
Topic archived. No new replies allowed.