Saturday, 5 July 2014

C++ program to illustrate function overloading(square)


Here is a C++ program to illustrate function overloading(square)


 SOURCE CODE OUTPUT
#include<iostream>
#include<iomanip>
using namespace std;
int square(int a)
{
   return a*a;
}
long square(long a)
{
   return a*a;
}
float square(float a)
{
    return a*a;
}
double square(double a)
{
    return a*a;
}
int main()
{
    cout<<"Square of 10      : "<<square(10)<<endl;
    cout<<"Square of 1000    : "<<square(1000L)<<endl;
    cout<<"Square of 102.5   : "<<setprecision(8)<<square(102.5F)<<endl;
    cout<<"Square of 103.436 : "<<setprecision(15)<<square(103.436)<<endl;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment