Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

find smallest number in array in c

#include<stdio.h>
 
int main() {
   int i, num, smallest;
 
   printf("
Enter no of elements :");
   scanf("%d", &num);
   int a[num];
   //Read n elements in an array
   for (i = 0; i < num; i++)
      scanf("%d", &a[i]);
 
   //Consider first element as smallest
   smallest = a[0];
 
   for (i = 0; i < num; i++) {
      if (a[i] < smallest) {
         smallest = a[i];
      }
   }
 
   // Print out the Result
   printf("
Smallest Element : %d", smallest);
 
   return (0);
}
Source by www.c4learn.com #
 
PREVIOUS NEXT
Tagged: #find #smallest #number #array
ADD COMMENT
Topic
Name
3+6 =