C Program to Find Smallest Element in Array

Google Advertisements

Prev Tutorial Next Tutorial

Find Smallest Element in Array Program in C

To write this code we receive input from user and store in array variable after that sort array elements and find smalles element.In this Code, we will find the smallest element of array by using linear search. Given an array of N elements, we have to find the Smallest Element of Array.

Examples To C Program Find Smallest Element from Array

Example

Array : [29, 12, 11, -16, -14, 13, 0, -3]
Smallest Element : -6

To understand below example, you have must knowledge of following C programming topics; String in C, for looping statements we need know For Loop in C and Array in C.

Algorithm to Find Smallest Element of Array

  • First take input from user as a size of Array
  • Then ask user to enter elements in Array
  • Initialize one variables smallest with first element of inputArray.
  • Using Loop traverse array from 0 to N-1 and compare each element with smallest. If current element is less than smallest, then update smallest with current element.
  • After array traversal smallest will have the smallest element.

C Program to Find Smallest Elements from Array

#include<stdio.h>
#include<conio.h>

 void main()
  {
    int array[100], count, i, smallest;
    clrscr();  
    printf("Enter Number of Elements Want in Array\n");
    scanf("%d",&count);

    printf("Enter Any %d count Elemnts in Array \n", count);
      
    // Read array elements
    for(i = 0; i < count; i++){
        scanf("%d",&array[i]);
    }
     
    smallest = array[0];
    // search num in inputArray from index 0 to elementCount-1 
    for(i = 0; i < count; i++){
	if(array[i] < smallest){
	    smallest = array[i];
	}
    }

    printf("Smallest Element in Array is: %d",smallest);
 
 getch();
}

Output

Enter Number of Elements in Array: 5
Enter Any 5 Elements in Array
4
-2
1
7
8
Smallest Element in Array is: -2
c program to find smallest elements form array
Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483