Â
In this, we are going to  find nth root of a number with the help of C++ program.
The Code given below can be used in Turbo C++ Compiler.
// nth root of a number Eg. num ^(1/n) #include<iostream.h> #include<conio.h> #include <math.h> // this is necessary for power, sqrt etc... void main() { clrscr(); int a =243; // you can take any nth root Eg : // 3^5 = 243 therefore 243^(1/5) = 3 double b = pow(a, (1.0 / 5)); cout<<"a ^ (1/5) = "<<b<<endl; int c; int n; cout<<"Enter an interger value of c whose nth root you want to find"<<endl; cin>>c; cout<<"Enter an interger value of n to take nth root of "<<c<<endl; cin>>n; cout<<n<<"th root of "<<c<<" = "<<c<<" ^ 1/"<<n<<" = "<< pow( c , 1.0/n)<<endl; getch(); }
// nth root of a number Eg. num ^(1/n)
#include<iostream>
#include <math.h>
// this is necessary for power, sqrt etc...
using namespace std;
int main()
{
int a =243;
// you can take any nth root Eg :
// 3^5 = 243 therefore 243^(1/5) = 3
double b = pow(a, (1.0 / 5));
cout<<"a ^ (1/5) = "<<b<<endl;
int c;
int n;
cout<<"Enter an interger value of c whose nth root you want to find"<<endl;
cin>>c;
cout<<"Enter an interger value of n to take nth root of "<<c<<endl;
cin>>n;
cout<<n<<"th root of "<<c<<" = "<<c<<" ^ 1/"<<n<<" = "<< pow( c , 1.0/n)<<endl;
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP