Find Smallest Number using Array in C++


Example Program:

Here is the simple program for printing the smallest number using array in C++.

Source Code

#include <iostream>
using namespace std;
int smallestelement(int arr[],int n)
{
  int temp=arr[0];
  for(int i=0;i<n;i++)
  {
    if(temp>arr[i])
    {
       temp=arr[i];
    }
  }
  return temp;
}
int main()
{
  int n;
  cout<<"Enter the size of array: ";
  cin>>n;
  int arr[n-1];
  cout<<"Enter array elements: ";
  for(int i=0; i<n; i++)
  {
    cin>>arr[i];
  }
  int smallest = smallestelement(arr,n);
  cout<<"Smallest Element is: "<<smallest;
  return 0;
}
To download raw file Click Here

Output

Enter the size of array: 5 
Enter array elements: 11
12
13
14
15
Smallest Element is: 1

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes