Write a program to calculate the minimum of two and three numbers of any data type


 

/* Write a program to calculate the minimum of two and three numbers of any data type*/

#include<iostream.h>

#include<conio.h>

template<class t>

t min(t a,t b)

{

return(a>b?a:b);

}

template<class t>

t min(t a,t b,t c)

{

return(a<b?(a<c?a:c):(b<c?b:c));

}

void main()

{

clrscr();

cout<<“\n min of 2int values=”<<min(10,20);

cout<<“\n min of 2float values=”<<min(2.75,2.5);

cout<<“\n min of 3int values=”<<min(15,5,20);

cout<<“\n min of 3float values=”<<min(3.1,4.1,5.1);

cout<<“\n min of 3char values=”<<min(‘a’,’x’,’y’);

getch();

}

/* output:

min of 2int value=20

min of 2floot values=2.75

min of 3int values=5

min of 3float values=3.1

min of 3char values=a*/

Related Posts

Comments are closed.