/* Function Overloading :: All Function names are same but, arguments are of different types and different quantities */
#include <iostream.h>
#include <conio.h>
// Function 1
void themax(int a)
{
cout<< "\n The maximum number is = " << a;
}
// Function 2
int themax(int m, int n)
{
(m>n ? return m : return n);
}
// Function 3
int themax( int arr[ ])
{
int max = arr[0];
for(int i = 1; i < n ; i++)
{
if( max < arr[i] )
max = arr[i];
}
return max;
}
void main()
{
int a[10], int x , y , max;
/* Function 1 calling ...demonstrated */
cout<< "\n Enter 2 numbers ";
cin >> x >> y;
if(x>y)
themax(x);
else
themax(y);
getch();
/* Function 2 calling ...demonstrated */
cout<< "\n Enter 2 numbers ";
cin >> x >> y;
max = themax(x,y);
cout<< The Maximum between " << x << " and " << y << " is " << max ;
getch();
clrscr();
/* Function 3 calling ...demonstrated */
for(int i = 0; i < 10 ; i ++)
{
cout<< "\n Enter an integer ";
cin >> a[i];
}
max = themax(a);
cout<< "\n\n The maximum value is " << max ;
getch();
}
No comments:
Post a Comment