Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2012, 09:33 AM
Registered User
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default I need a help.

Quote:
how to be a problem here, my code does not calculate the complex roots, the code only calculates the real roots
Code:
//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;

}
my code can't calculated a complex root, imaginare numbers. i don't know how can i used this library #include <complex.h>

Last edited by undead; April 17th, 2012 at 10:36 AM..









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.