Wednesday 15 February 2012

C++ program using overloading function to find the minimum using min() function

Overloading function to find the minimum using min() function

# include<iostream.h>
# include <conio.h>
int min(int a, int b)
{
if (a<b)
return(a);
else
return(b);
}
char min(char a, char b)
{
if (a<b)
return(a);
else
return(b);
}
double min(double a, double b)
{
if (a<b)
return(a);
else
return(b);
}
void main()
{
int n, n1;
char ch, ch1;
double d, d1;
clrscr();
cout << "Enter two integers ";
cin >> n >> n1;
cout << "Enter two characters ";
cin >> ch >> ch1;
cout << "Enter two double precision quantity ";
cin >> d >> d1;
cout << "\nMinimum of two integer "<<min(n,n1);
cout << "\nMinimum of two characters "<<min(ch,ch1);
cout << "\nMinimum of two double precision quantity "<<min(d,d1);
}

step by step explanation:

1.the header file "iostream.h" is used to include the function cin and cout.
2.the header file"conio.h"is used to include the function like getch and clrscr.
3.int min is a function of int type .
4.char min is also a int type function.
6.double min is also a int type function.
7.void main is also a void type function it is worked under the curley brackets.

No comments:

Post a Comment