Question #191855

Implement a C++ program to overload the function named as sum, to perform sum of two integer and perform sum of float two number respectively.


Expert's answer

#include<iostream>
using namespace std;
int sum(int a,int b)
{
    int sum;
    sum=a+b;
    return sum;
}
float sum(float a,float b)
{
    float sum;
    sum=a+b;
    return sum;
}
int main()
{
    int a,b;
    float c,d;
    cout<<"Enter two integer numbers ";
    cin>>a>>b;
    cout<<"\nSum of two integer numbers = "<<sum(a,b);
    cout<<"\nEnter two float values ";
    cin>>c>>d;
    cout<<"\nSum of two float values = "<<sum(c,d);
}

LATEST TUTORIALS
APPROVED BY CLIENTS