27.8.15

Define a function template for finding the minimum value contained in an array

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 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 aray 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 elements is:\n"; cout<<min1;
cout<<"\nThe minimum floating elements is :\n";

cout<<min2;

getch();

return 0;

}

************************************OUTPUT******************************

enter the size value: 5

enter the integer aray elements 20 30 10 38 28



 enter the floating array elements 20.4 19.7 14.8 1.7 2.6


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

No comments:

Post a Comment

Comment Here