Define a function template for finding the minimum value contained in an array. Write main( ) function to find the minimum value of integer array and the minimum value of floating point numbers in an array.




#include<iostream.h>
#include<conio.h>
template<class T>
T minimum(T a[],int size)
{
T min=a[0];
for(int i=0;i<size;i++)
{
if(a[i]<min)
min=a[i];
}
return min;
}
int main()
{
int a[10],size,i,min1;
float b[10],min2;
clrscr();
cout<<"Enter the size value:\n";
cin>>size;
cout<<"Enter the integer array elements\n";
for(i=0;i<size;i++)
cin>>a[i];
cout<<"Enter the floating array elements\n";
for(i=0;i<size;i++)
cin>>b[i];
min1=minimum(a,size);
min2=minimum(b,size);
cout<<"The minimum integer element is:\n";
cout<<min1;
cout<<"\nThe minimum floating element is :\n";
cout<<min2;
getch();
return 0;
}

The output of the above program is:
Enter the size value:
5
Enter the integer array elements
20
30
10
38
28
Enter the floating array elements
20.4
19.7
14.8
1.7
2.6

The minimum integer element is:
10
The minimum floating element is :
1.7





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: