C-programming - To find smallest number in an array, C program to find smallest number

To find smallest number in an array

This program finds the smallest of numbers


#include<stdio.h>
#include<conio.h>
 
main() 
{
    int array[100], minimum, size, c, location = 1;
 
    printf("Enter the number of elements in array\n");
    scanf("%d",&size);
 
    printf("Enter %d integers\n", size);
 
    for ( c = 0 ; c < size ; c++ )
        scanf("%d", &array[c]);
 
    minimum = array[0];
 
    for ( c = 1 ; c < size ; c++ ) 
    {
        if ( array[c] < minimum ) 
        {
           minimum = array[c];
           location = c+1;
        }
    } 
 
    printf("Minimum element is present at location number %d and it's value is %d.\n", location, minimum);
    return 0;
}

An array of elements is got from the user as input by using a for loop. Now the first element of array is assigned as minimum. Then each number in the array is checked to be higher than it. If not higher, then that number is assigned to the minimum and then again compared with each number in an array. Thus the smallest number is found.

output

Enter the number of elements in array
5
Enter 5 numbers
5
4
3
7
1
2
Minimum element is present at location number 5 and its value is 1.

The topic on C-programming - To find smallest number in an array is posted by - Maha

Hope you have enjoyed, C-programming - To find smallest number in an arrayThanks for your time

Tech Bluff