Secant Method ideas for a function

Hi there,i am new in c++ and i am learning by my self, from google, wiki etc. you know and I want to make some programs.
first i want to make a program that calculates the degree of a number.
example code :

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{int num;
double a;
cout <<"Please enter the numer";
cin>>num;
do (a=a+0.1)
while (a*a=num);
cout<<a;

For some reason it doesnt work.

This should calculate the degree of the num right?
and also how can i make a code so it calculates the root of a single num?
Something like :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <cmath>
using namespace std;

double f(double x)
{
num - x*2}
int main ()

{int num;
double a;
cout <<"Please enter the numer";
cin>>num;

cout<<x;

or not??
John Taylor
Last edited on
What is the root of a single number?
f(x) = n it has no roots if n!=0
Last edited on
I mean in mathematics, the nth root of a number x is a number r which, when raised to the power of n, equals to x

For example:

2 is a 4th root of 16, since 24 = 16;

so how can i find it?
is my code right?
Last edited on
This:

1
2
3
4
double f(double x)
{
    return x*x*x-64;
}

should give you 4 (3-rd root of 64).

This:

1
2
3
4
double f(double x)
{
    return x*x-25;
}

should give you 5 (square root of 25).
ok i will try to make sth using that.More ideas will be appreciated!
Last edited on
Come on give me some advise on how to calculate the degree!
Last edited on
You could define as
1
2
3
double f(double x, double n, int exp){
  return mypow(x, exp)-n; 
}

Last edited on
Never mind.I started another project.
Topic archived. No new replies allowed.