## Find smallest element in an array using C

C program to find smallest element of any array. To find that number we will assume the first element as the smallest number among all other numbers of that array. Then compare it with other elements and take the new smallest number if the second number is smaller than that number.

However, you can write code to serve this purpose in different way using function, recursion or pointer. Let’s see some program to take the idea to do this.

## C program to find smallest element of array

``````// find smallest number of an array in C

#include <stdio.h>

int main(){
int y, num_array, arr_size, indx = 0;

printf("Enter how many number you have for the array : ");
scanf("%d", &arr_size);

printf("Enter all array elements here : \n", arr_size);

for(y = 0; y < arr_size; y++){
scanf("%d", &num_array[y]);
}

for(y = 1; y < arr_size; y++){
if(num_array[y] < num_array[indx]){
indx = y;
}
}

printf("\nMinimum element at location %d and it is = %d.\n", indx + 1, num_array[indx]);
return 0;
}``````

### Output of smallest element program: We can do the same program using function, recursion or pointers. You can also count that how many times the maximum number remains in our array. For doing this simply you can take another variable for count the occurrence. Try this program in your own. Now we will see the program to find smallest integers of an array using pointer in C.

## Find smallest element of array using pointer in C

``````// find smallest number of an array using pointer in C

#include <stdio.h>

int main(){
int a, *min_num, arr_size, indx = 1, my_array;

printf("Enter how many number of the array : ");
scanf("%d", &arr_size);

printf("Enter all array element here : \n");

for(a = 0; a < arr_size; a++){
scanf("%d", &my_array[a]);
}

min_num = my_array;
*min_num = *my_array;

for(a = 1; a < arr_size; a++){

if(*(my_array + a) < *min_num){
*min_num = *(my_array + a);
indx = a + 1;
}
}

printf("\nMinimum number at location %d which is = %d.\n", indx, *min_num);
return 0;
}``````

### See program output here :

``````Enter how many number of the array : 12
Enter all array element here :
65 45 34 65 75 32 62 18 54 24 29 50

Minimum number at location 8 which is = 18.``````

Previous pageLargest element in array

Next pageReverse array