PDA

View Full Version : جدول هرنر



minazare
شنبه 28 اسفند 1389, 09:21 صبح
میشه درباره جدول هرنر وطرز استفادش برای به دست آوردن چند جمله توضیح بدین

NIMA_1981
شنبه 28 اسفند 1389, 09:48 صبح
این الگوریتم روشی برای بدست آوردن مقدار یک چند جمله ای در یک نقطه است
Description:This program uses the Horner's algorithm, to convert numbers from X numeric system into decimal.



//Including the libraries #1
#include <iostream.h>
#include <string.h>
//End of #1
//Defining the variable #2
char a[100];
int len;
int sys;
int b[100];
int now;
//End of #2
//Main function #3
void main()
{
cout << "This program converts a number from X entered by you numeric system, into decimal"
<< "Enter a number : ";
cin >> a;
len=strlen(a);
cout << "Enter the numeric system of your number : ";
cin >> sys;
b[0]=(a[0]-48);
//The cycle...
for (now=0;now<len;now++)
{
b[now+1]=b[now]*sys + (a[now+1]-48);
}

//Returns the result
cout << a<<"("<<sys<<") is "<<b[len-1]<<"(10)"<<endl;

}

NIMA_1981
شنبه 28 اسفند 1389, 09:54 صبح
به این لینک هم نگاه کن کمک میکنه

http://en.wikipedia.org/wiki/Horner_scheme