How to use a for loop in C language to find the minimum value
In C language, you can use a for loop to find the minimum value. Here is an example code for finding the minimum value.
#include <stdio.h>
int main() {
int arr[] = {4, 2, 7, 5, 1};
int size = sizeof(arr) / sizeof(arr[0]);
int min = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
printf("最小值为 %d\n", min);
return 0;
}
In the above code, iterate through the array using a for loop, and compare it with the current minimum value during each iteration. If the current element is less than the minimum value, update the minimum value to be the current element. Ultimately, the minimum value after the loop ends will be the smallest value in the array.