Wednesday, October 26, 2016

Minimum Element In An Array with Anonymous Datatype:)

Tags

Following Program Find Minimum Element Using Function Template:

#include<iostream>
using namespace std;
template<class T>
T min(T a[],int n)
{
T min=a[0];
for(int i=0;i<n;i++)
if(min>a[i])
{
min=a[i];
}
return min;
}
main()
{   int n,a[100];
cout<<"Enter The No of Elements\n";
    cin>>n;
    cout<<"Enter The Elements\n";
    for(int i=0;i<n;i++)
    cin>>a[i];
    cout<<"Minimum Value is: "<<min(a,n);
}
Output: