Find elements

Cpp program to display smallest number of an Array

Cpp program to display smallest number of an Array

In this tutorial, we will discuss the concept of Cpp program to display smallest number of an Array.

In this topic, we will learn how to find the smallest elements of array elements in Cpp programming 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 using for loops.

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

  • array declaration
  • Essential variable declaration
  • Get input from the user for array length
  • Get input from the user for array elements
  • loop for finding the largest value
  • Display result on the screen

Find smallest elements from integer Array

program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int arr[30]; //array declaration
    int length,i,min;//essential variable declaration
    cout << "Enter the length of the array: ";
    cin>>length;
    for(i=0; i<length; i++){
        cout<<"Enter elements "<<i+1<<" :";//enter elements for array
        cin>>arr[i];//store the element in array
    }
    min=arr[0];//assume the first elements as smallest number
    for(i=0; i<length; i++){
    if(min>arr[i]){
        min=arr[i];
    }
    }
    cout<<"\nsmallest elements is: "<<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: 6

Enter element 1: 56
Enter element 2: 34
Enter element 3: 78
Enter element 4: 21
Enter element 5: 76
Enter element 6: 43
Smallest element is: 21

Find smallest elements from float Array

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    float arr[30],min; //array declaration
    int length,i;;//essential variable declaration
    cout << "Enter the length of the array: ";
    cin>>length;
    for(i=0; i<length; i++){
        cout<<"Enter elements "<<i+1<<" :";//enter elements for array
        cin>>arr[i];
    }
    min=arr[0];//assume the first elements as smallest number
    for(i=0; i<length; i++){
    if(min>arr[i]){
        min=arr[i];
    }
    }
    cout<<"\nsmallest elements is: "<<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: 6
Enter element 1: 34.2
Enter element 2: 54.1
Enter element 3: 8.5
Enter element 4: 23.5
Enter element 5: 47.6
Enter element 6: 51.3

smallest element is: 8.5

Similar post

C code to smallest among three numbers

C++ code to smallest among three numbers

Python code to smallest among three numbers

 

Java code to find smallest of three numbers using method

C code to smallest among three numbers using function

C++ code to smallest among three numbers using function

Python code to smallest among three numbers using function

 

Java code to find smallest of three numbers using ternary operator

C code to smallest among three numbers using ternary operator

C++ code to smallest among three numbers using ternary operator

 

Suggested for you

Addition of two numbers in Java

Addition of two numbers in C

Addition of two numbers in C++

Addition of two numbers in Python

Addition of two numbers in C#

Addition of two numbers in PHP

Addition of two numbers in JavaScript

 

Sum of two numbers in Java using method

Sum of two numbers in C++ using function

Sum of two numbers in Python using function

 

C program to add two numbers without using arithmetic operators

C++ program to add two numbers without using arithmetic operators

Python program to add two numbers without using arithmetic operators

 

For loop in C++ language

While loop in C++language

The function in C++ language

 

Operator in C language

Function in C language

Data type in C language

Operator in C++ language

Data types  in C++ language

 

Single dimension Array in C++ language

If statements in C++

Data type in C++ programming language

Cpp program to display smallest and largest number in Array
Cpp program to biggest and smallest of three numbers
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago