I am trying to create a C function that takes an array, finds the smallest element, and sets the value of that element to zero.
This is my function so far.
void find_minimum(double a[], int n) {
int i, smallest = 0;
smallest = a[0];
for (i = 0; i < n; i++) {
if (a[i] < smallest) {
smallest = a[i];
}
a[i] = 0;
}
}
When I run it, every index except the last one is zero, but I want only the smallest element to be zero.
a[i] = 0 ;inside theifstatement, and start comparison from the index 1 i.e.i=1in for loop