Find Square Root of a Number in C++

Advertisements

Find LCM of Two Number Program in C++ Find Cube Root of Number Program in C++

C++ program to find Square Root of a Number

For calculate Square Root of a number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5. And one another method for this program is use sqrt() function it is pre-defined in math.h header file.

C++ program to find Square Root

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main() 
{ 
int num,ans; 
clrscr(); 
cout<<"Enter any Num: "; 
cin>>num; 
ans=pow(num,0.5);
cout<<"\n Squre of "<<num<<" is: "<<ans; 
getch(); 
} 

Output

Enter any Num: 9
Squre of 9 is: 3

Explanation of Code

pow() is a predefined function in math.h header file, it is used for calculate power of any number.

C++ program to find Square Root

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main() 
{ 
int num,ans; 
clrscr(); 
cout<<"Enter any Number: "; 
cin>>num; 
ans=sqrt(num);;
cout<<"\n Squre of "<<num<<" is: "<<ans; 
getch(); 
} 

Output

Enter any Number: 9
Squre of 9 is: 3

Explanation of Code

sqrt() is a predefined function in math.h header file, it is used for calculate square root of any number.

Find Square Root By passing values in Function

Example

#include<iostream.h>
#include<conio.h>
#include<math.h>

int square(int); 
void main()
{
int num;
clrscr();
cout<<"Enter any Num: ";
cin>>num;
cout<<"\n Square of "<<num<<" is: "<<square(num));
getch(); 
}
int square(int num)
{
int ans;
ans=pow(num,0.5);
return(ans); 
getch();
}

Output

Enter any Num: 64
Square of 3 is: 4

Find LCM of Two Number Program in C++ Find Cube Root of Number Program in C++

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements