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 number to find in an 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[5],num;

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

	printf("\n Enter any number:- ");
	scanf("%d",&num);

	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 array elements(Max 5 elements):- 40 45 30 100 102

 Enter any number:- 4

 The minimum number in the given array is 30 
*/