This is the C program that I've written to find the least element in the given array.
But the output is "0" every time. I've checked other websites too but I found no problem in my program. Can anyone please rectify the problem in this program. (Thanks in advance)
#include <stdio.h>
main()
{
int i,least,x[10];
printf("Enter the elements into the array\n");
for (i=0;i<10;i++)
{
scanf("%d",&x[10]);
}
least=x[0];
for (i=1;i<10;i++)
{
if(least > x[i])
{
least=x[i];
}
}
printf("The least element in the array is %d", least);
}
xhas space for. 2) What&x[10]means.&x[i]in yourscanf(). Right now you always wrote to the 11th element of the array, leading to a buffer overflow btw.