Here is a C++ program to find sum of numbers using function overloading
SOURCE CODE OUTPUT
#include<iostream>
#include<iomanip>
using namespace std;
int add(int a,int b)
{
return a+b;
}
float add(float a,int b)
{
return a+b;
}
float add(int a,float b)
{
return a+b;
}
float add(float a,float b)
{
return a+b;
}
int main()
{
cout<<"12 + 13 = "<<add(12,13)<<endl;
cout<<"12.6 + 9 = "<<add(12.6F,9)<<endl;
cout<<"52 + 8.25 = "<<add(52,8.25F)<<endl;
cout<<"65.32 + 95.4 = "<<add(65.32F,95.4F)<<endl;
return 0;
}
#include<iomanip>
using namespace std;
int add(int a,int b)
{
return a+b;
}
float add(float a,int b)
{
return a+b;
}
float add(int a,float b)
{
return a+b;
}
float add(float a,float b)
{
return a+b;
}
int main()
{
cout<<"12 + 13 = "<<add(12,13)<<endl;
cout<<"12.6 + 9 = "<<add(12.6F,9)<<endl;
cout<<"52 + 8.25 = "<<add(52,8.25F)<<endl;
cout<<"65.32 + 95.4 = "<<add(65.32F,95.4F)<<endl;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment