C Program To Find Smallest Element in Array

C Program To Find Smallest Element in Array

#include<stdio.h>

int main()
{

   int a[30], i, num, smallest;

   printf("Enter no of elements :\n");
   scanf("%d", &num);  //input from user

   for (i = 0; i < num; i++)
    {
     scanf("%d", &a[i]);  //elements entry in array
    }

   smallest = a[0];

   for (i = 0; i < num; i++)
   {
      if (a[i] < smallest)
 {
         smallest = a[i];   //do sorting in asending order and first element of array is smallest
      }
   }

   printf("Smallest Element : %d\n", smallest);   //Print Output On screen

}

Related Posts