Thursday 26 June 2014

C++ program to find smallest element in array


Here is a C++ program to find smallest element in array


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a[20],num,min;
    cout<<"How many elements to be stored (max 20) : ";
    cin>>num;
    cout<<"Enter elements of array : ";
    for(int i=0;i<num;i++)
        cin>>a[i];
        min=a[0];
    for(int i=0;i<num;i++)
        if(min>a[i])
            min=a[i];
    cout<<"Smallest element in array : "<<min;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment