For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!
Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
by undead » Tue Apr 17, 2012 11:17 pm
My code can't calculated a complex root, imaginare numbers. i don't know how can i used this library #include <complex.h>, please correct my code and show me errors please.
- Code: Select all
//horner's polynomial soln, synthetic division
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <math.h>
using namespace std;
int main()
{
int it, n, i;
double *a,*b,*c,x=-1000;
cout<<"Enter the degree of the polynomial:";
cin>>n;
a=new double [n];
b=new double [n];
c=new double [n];
cout<<"Enter the coefficients of the polynomial"<<endl;
for ( i = 0; i < n; i++ )
cin >> a[i];
do
{
it = 0;
c[0] = a[0];
b[0] = a[0];
do
{
for ( i = 1; i < n; i++ )
b[i] = a[i] + x*b[i-1];
for ( i = 1; i < n; i++ )
c[i] = b[i] + x*c[i-1];
x = x - b[n]/c[n-1];
it++;
}
while (abs( b[n]) > 1e-5 && it<100 );
cout << "The root is:" << x << endl;
n--;
for ( i = 0; i < n; i++ )
a[i] = b[i];
}
while( n >= 1 );
getch();
return 0;
}
-
undead
-
- Posts: 1
- Joined: Tue Apr 17, 2012 11:11 pm
-
by schloob » Wed Apr 18, 2012 9:23 pm
i advise: learn to state your problem more precisely
:]
-

schloob
-
- Posts: 1853
- Joined: Mon Feb 16, 2004 10:29 am
- Location: Seattle
-
Return to For Beginners
Who is online
Users browsing this forum: No registered users and 4 guests