In this tutorial you will learn about the C Program to Find Minimum Element in Array and its application with practical example.
C Program to Find Minimum Element in Array
In this tutorial, we will learn to create a C program that will find the Minimum Element in Array using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C Programming.
- Creating and Using the user-defined function in C programming.
The minimum value of array:-
As we all know array is a collection of similar data type elements. In an array, only one variable is declared which can store multiple values. The index value of the array start’s from “0” if the array is having size 5 i.e. a[5] = { 1, 2, 3, 4, 5 } values can be stored in that array. Now the a[0] = 1 , a[1] = 2, a[2] = 3, a[3] = 4, a[4] = 5. On the array, we can do many operations with the help of the c language.
We will find the minimum size element with the help of conditional statements.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
STEP 1: START STEP 2: INITIALIZE arr[] = {25, 11, 7, 75, 56} STEP 3: length= sizeof(arr)/sizeof(arr[0]) STEP 4: min = arr[0] STEP 5: SET i=0. REPEAT STEP 6 and STEP 7 UNTIL i<length STEP 6: if(arr[i]<min) min=arr[i] STEP 7: i=i+1. STEP 8: PRINT "Smallest element present in given array:" by assigning min STEP 9: RETURN 0. STEP 10: END. |
Program:-
To find minimum value element from array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h> int main() { int array[100], size, i, location = 0; //Declaring the variables in the program. //Taking the size of array input from the user printf("Enter number of elements in array\n"); scanf("%d", &size); //Taking elements of array as input from user printf("Enter %d integers\n", size); for (i = 0; i < size; i++) scanf("%d", &array[c]); for (i = 1; i < size; i++) if (array[c] < array[location]) location = i; //Printing output of the program to user printf("Minimum element is present at location %d and its value is %d.\n", location+1, array[location]); return 0; } |
Output:-
In the above program we have first initialized the required variable
- location = it will hold the location of array elements.
- array[100] = it will hold the elements in an array.
- i = it will hold the integer value to control the array.
- size = it will hold the size of the array.
Printing output of the program to user
Program Code