Write a program for addition using function overloading .
#include<iostream .h>
#include<conio.h>
int sum(int,int);
float sum(float,float); double sum(int,float);
int sum(int a,int b)
int sum(int a,int b)
{
return(a+b);
}
float sum(float x,float y)
{
return(x+y);
}
double sum(int
p,float q)
{
return(p+q);
}
void main()
{
clrscr();
cout<<"Double's
sum="<<sum (5,2.3f);<<endl;
cout<<"Int' s sum="<<sum (5,5);<<endl;
cout<<"Float' s sum="<<sum(5.5f,3.2f);<<endl;
getch();
}
Output:
Double's sum=7.3
Int's sum=10
Float's sum=8.8
No comments:
Post a Comment