Saturday 18 February 2012

C++ program to find the square root of different integers.


C++ program to find the square root of different integers.

# include"iostream.h"
# include"math.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 explaination:
1.Header file "iostream" is used to including the function and cin and cout.
2.Header file "math.h" is used to calculating the mathematical function.
3.Main is also a function of void type it is worked untill the curley brackets.

1 comment:

  1. You have used,sqrt function here. What if I want to make this program without sqrt function ???

    ReplyDelete