Write a function called findmin that accepts an array of in

Write a function called find_min () that accepts an array of integers and the number of items in the array as parameters, and returns the smallest number in the array.

Solution

Min.c

#include <stdio.h>
int find_min(int a[], int n);
int main()
{
int min, a[] = {4,3,5,7,6,1,8,9,2,10};
  
min = find_min(a,10);
printf(\"The smallest number is %d\ \",min);
return 0;
}

int find_min(int a[], int n){
int i, min = a[0];
for(i=1; i<n; i++){
if(min > a[i]){
min = a[i];
}
}
return min;
}

Output:

sh-4.3$ gcc -o main *.c                                                                                                                                                                                                         

sh-4.3$ main                                                                                                                                                                                                                    

The smallest number is 1

 Write a function called find_min () that accepts an array of integers and the number of items in the array as parameters, and returns the smallest number in th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site