Description
Write a function to return the smallest element in an array of integers with the following function header:
int smallestElement(int array[], int size)
Hint
You should submit the implementation of the function but do not submit the main() function.
main.c
#include <stdio.h>
#include "1089.h"
int list[105];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d", &list[i]);
printf("%d\n", smallestElement(list, n));
return 0;
}
1089.h
int smallestElement(int array[], int size);
My code:
// Date:2020/4/18
// Author:xiezhg5
int smallestElement(int array[], int size)
{
int i,Min=array[0]; //先赋初值
for(i=1;i<size;i++)
{
//遍历进行比较
if(array[i]<Min)
{
Min=array[i];
}
}
return Min;
}