In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
#include <math.h>
// function to calculate root
int root()
{
int a,n;
clrscr();
cout<<"Enter value of a"<<endl;
cin>>a;
cout<<"enter the nth root you want to calculate \n";
cin>>n;
float ans;
ans = pow(a,(1.0/n));
cout<<"The root of the number is "<<ans;
return ans;
}
// main function to call the root function
void main()
{
// calling root function
root();
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
#include <math.h>
using namespace std;
// function to calculate root
int root()
{
int a,n;
cout<<"Enter value of a"<<endl;
cin>>a;
cout<<"enter the nth root you want to calculate \n";
cin>>n;
float ans;
ans = pow(a,(1.0/n));
cout<<"The root of the number is "<<ans;
return ans;
}
// main function to call the root function
int main()
{
root();
return 0;
}
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP