www.computerscienceai.com provides resources like python programs, c programs, java programs, c++ programs, php programs, html and css free resources, articles and "how to" tutorials on computer, science, artificial intelligence and tech world.
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.
Start
Declare integer array, a variable to store number to find in an array and a counter variable 'i'.
Accept the array using for loop.
Define a function which accepts an array and size of array.
Return the minimum number in an array from the function defined above.
Display the minimum number in an array.
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
*/