write a program to calculate the square root of given number
We know that to calculate square root of number we have to multiply given number by 0.5 because square root of number it means power of 1/2 and 1/2=0.5.
The code for this program is as follows:
cout <<"Enter any Number: ";
cout <<"\n Squre of "<<num<<" is: "<<ans;
#include<iostream.h> used for input/output of data
#include<conio.h> provides several functions like clrscr(), getch() etc.
After that in main() function we have declared a variables num, ans; after that we have used clrscr(); function to clear the scree when program will run. It will clear the previous output from any program. Now we have used the cout function that shows message “Enter any Number :”; and when we enter any number then this number is read by cin function and assign to num variable. Here we have used pow() function which is predefined function in math.h header file, it is used to calculate power of any number. And using this we assign the result from the pow() function to the ans variable. And print the result using cout.
The output is as follows: