View All C Programs

 Previews Example  View All C Programs Next Example 

Program to find smallest number in array in C

This program to find smallest (minimum) number in array Array is a collection of similar types of elements. We can find minimum or maximum element in an array by using comparison operator. Traversing all the elements and comparing these elements pair wise one by one.
#include <stdio.h>
#include <conio.h>
    main()
{
     int mat[20];
     int s,min;
     printf("\nSize of your Array is : ");
     scanf("%d",&s);
     printf("\nEnter your %d element of an array : ", s);

    for(int i=0;i < s;i++)
     {
          scanf("%d",&mat[i]);
     }

     min=mat[0];
     for(int i=1;i < s;i++)
     {
          if(min>mat[i])
          min=mat[i];
     }

     printf("\n Minimum element is from given %d element is : %d",min);
     getch();
}
Result
Size of your Array is : 5
Enter your 5 element of an array :
10
20
60
90
70
Minimum value element from given 5 element is : 10