S
sdlt85
Hi, I need some help.
My program is runing but it is not given me the right answer.
The program it suppost to solve a polynomial, using Horners.
The user will enter the value for x and the coefficients.
This is my code:
#include <iostream>
#include <iomanip>
using namespace std;
const int n = 100;
void HornerP(char[], int, int, int);
int main()
{
char P[n];
int x, c;
cout<<"Enter the value for x: ";
cin>>x;
cout<<"How many coefficients? ";
cin>>c;
for(int i=0; i<c; i++)
{
cout<<"The coefficients are: ";
cin>>P;
}
HornerP(P, n, x, c);
return 0;
}
void HornerP(char *a, int n, int x, int c)
{
int p=a[n];
for (int i=n-1; i>=n; i--)
{
p=x*p-a;
}
cout<<"You enter "<<c-1<<" degree polynomial and the answer is:
"<<p<<endl;
}
My program is runing but it is not given me the right answer.
The program it suppost to solve a polynomial, using Horners.
The user will enter the value for x and the coefficients.
This is my code:
#include <iostream>
#include <iomanip>
using namespace std;
const int n = 100;
void HornerP(char[], int, int, int);
int main()
{
char P[n];
int x, c;
cout<<"Enter the value for x: ";
cin>>x;
cout<<"How many coefficients? ";
cin>>c;
for(int i=0; i<c; i++)
{
cout<<"The coefficients are: ";
cin>>P;
}
HornerP(P, n, x, c);
return 0;
}
void HornerP(char *a, int n, int x, int c)
{
int p=a[n];
for (int i=n-1; i>=n; i--)
{
p=x*p-a;
}
cout<<"You enter "<<c-1<<" degree polynomial and the answer is:
"<<p<<endl;
}