C++ Codes
Algorithms
Algorithm Analysis in C++
Beginners
Code Snippets
Graphics
Data Structures
File Manipulation
Games
Mathematics
Miscellaneous
Visual C++ Library
C++ > Algorithms sample source codes
It evaluates the value of any polynomial of any degree, adds two poly
It evaluates the value of any polynomial of any degree, adds two poly and also multiplies them Code : /*evaluates, adds ,multiplies two polynomials p & f to evaluate poly of deg > 20 manipulate const in size */ #include
using namespace std ; void polyadd(float*a,int dega,float*b,int degb,float*sum) {int i ; if(dega>=degb) {for (i=0;i<=dega;i++) sum[i]=a[i]+b[i] ;} if(degb >dega) {for(i=0;i<=degb;i++) sum[i]= a[i]+b[i] ; } } //******************************************** /*void polymult(float*a,int dega,float*b,int degb,float*mult) {int i,j; if(dega<=degb) for(i=0;i<=degb;i++) {for(j=0;j<=i;j++) mult[i]= mult[i] + a[j]*b[i-j] ; mult[i] = mult[i] +a[i+1]*b[i+1] ; } //mult[i] = mult[i] - a[0]*b[0] ; } if (degb
>deg ; if(deg<0) cout<<"go learn ur textbook"<
=0) { cout<<"give the value of the coefficients"<
>a[j] ; cout<<"give the value x"<
>x ; ans = power(a,deg,x); cout<<"the value of p("<
>a[j]; */ cout<<" give in the degree of poly b"<
>degb ; cout<<"enter the values of the coefficient of polynomialb"<
>b[j] ; cout<<"give the value to be substituted in polynomialb"<
>y ; ans = power(b,degb,y) ; cout<<"the value of f("<
>decision ; if(decision =="a") { polyadd(a,dega,b,degb,sum); if (dega>=degb) {ans= power(sum,dega,x); cout<<"the answer after addition of p("<
dega) {ans = power(sum,degb,x) ; cout<<"the answer after addition of p("<
=degb) {ans= power(a,dega,x)*power(b,degb,y) ; //cout<<"the answer of multiplication"<
dega) //{ ans = power(mult,degb,x) ; cout<<"the answer after multiplication of p("<
Privacy Policy
|
Link to Us
|
Links