C Program to Find Minimum Number in an Array

Problem:

Write a C program to find minimum number in an array.

Algorithm or Solution:

Here is the algorithm or solution of C program to find minimum or smallest number in an array.
  1. Start
  2. Declare integer array, a variable to store size of array and a counter variable 'i'.
  3. Accept the array using for loop.
  4. Define a function which accepts an array and size of array.
  5. Return the minimum number in an array from the function defined above.
  6. Display the minimum number in an array.
  7. Stop.

C Program / Source Code:

Here is the source code of C program to find minimum or smallest number in an array.
/* Aim: Write a C program to find minimum number in an array. */ 

#include<stdio.h>

int Minarr(int arr[],int n); // Minarr Function Prototype

void main()
{
	int i,arr[20],num;

	printf("\n Enter size of array:- ");
	scanf("%d",&num);

	printf("\n Enter array elements:- ");
 
	for(i=0;i<num;i++)
		scanf("%d",&arr[i]);

	printf("\n The minimum number in the given array is %d \n \n",Minarr(arr,num));
 
}// End of the main() function

// Minarr Function to find minimum number in an array 
int Minarr(int arr[],int n)
{
	int i,min;
	min=arr[0];

	for(i=0;i<n;i++)
	{
		if(min>arr[i])
		min=arr[i];
	}
 
	return min;
}

/* Output of above code:-

 Enter size of array:- 5

 Enter array elements:- 40 45 30 100 102

 The minimum number in the given array is 30 
*/