Wednesday 15 February 2012

C++ program using function overlaoding for calculating the square root of the different numbers


Function overlaoding for calculating the square root of the different numbers

# include<iostream.h>
# include<conio.h>
int sroot(int n)
{
return(sqrt(n));
}
long int sroot(long int n)
{
return(sqrt(n));
}
double sroot(double n)
{
return(sqrt(n));
}
void main()
{
int num;
long int num1;
double num2;
cout << "Enter the value of num "; 

 cin >> num;
cout << "Enter the value of num1";

 cin >> num1;
cout << "Enter the value of num2 ";

 cin >> num2;
cout << "\nSquare root of int is " << sroot(num); 

 cout << "\nSquare root of long int is " << sroot(num1); 
 cout << "\nSquare root of double is " << sroot(num2); 
}

step by step explanation:

1.the header file "iostream.h" is used to include the function cin and cout.
2.the header file"math.h" is used to calculate the mathematical function.
3.sqrt is a int type function which is used to calculate the sqrt.
4.main is also a void type function which is worked during the curley brackets.

No comments:

Post a Comment