Site icon Codeforcoding

C program to find smallest number in an array

C program to find smallest number in an Array

In this tutorial, we will discuss the concept of C program to find the smallest number in an Array

In this topic, we will discuss how to find smallest number in an Array using for loop in C language

This program gets “n” number of elements and Enter the elements of the array as input from the user. then, this program finds and displays the smallest elements from the array.

find smallest number in an array

In this programs, we can see step by step procedure for completion of the program.

This is a C code to find the smallest number in an array using for loop

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int arr[30];//array declaration
    int length,i, min; //essential variable declaration
    printf("Enter the length of the array: ");
    scanf("%d", &length);//get input from user for length
    for(i=0; i<length; i++){
    printf("Enter element %d: ",i+1);//enter elements for array
    scanf("%d", &arr[i]);
    }
    min=arr[0];//assume first element as smallest number

    for(i=0; i<length; i++){//iterate for loop from first index of array
    if(min>arr[i]){
        min=arr[i];
    }
    }
    printf("\nSmallest elements is: %d",min);
getch();//display result on the screen
    return 0;
}

When the above code is compiled and executed, it produces the following results

Enter the length of the array: 5
Enter element 1: 46
Enter element 2: 21
Enter element 3: 67
Enter element 4: 87
Enter element 5: 43

Smallest elements is: 21

 

Similar post

 largest number of three number in C

 largest number of three number in C++

 largest number of three number in Python

 largest number of three number in C using function

 largest number of three number in C++ using function

 largest number of three number in Python using function

 largest number of three number in Java using method

 

Suggested for you

Operator in C language

For loop in C language

If statements in C language

Data type in C language

Single dimension array in C language

C program to find smallest and largest number in an array
Cpp program to display smallest and largest number in Array
Exit mobile version