Add to Favorites    Make Home Page 143 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Algorithms Home » polynomial

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title polynomial
Author niravres
Author Email neo_pathak [at] yahoo.com
Description it evaluates the value of any polynomial of any degree,adds two poly and also multiplies them
Category C++ » Algorithms
Hits 367634
Code Select and Copy the Code
Code : /*evaluates, adds ,multiplies two polynomials p & f to evaluate poly of deg > 20 manipulate const in size */ #include <iostream.h> 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<dega) {for(i=0;i<=dega;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] ;} }*/ //******************************************************** double power(float*a,int n,float x) {float val=0,prod=1 ; int i ; for(i=0;i<=n;i++) {val = val+a[i]*prod; prod = prod*x ;} return val ; } //******************************************************** double power(float*a,int n,float x); main() {const int size=20 ; int deg,j ; float a[size], x ; for(j=0;j<=size-1;j++) a[j] = 0.0 ; double ans ; cout<<"give the degree of the polynomiala "<<endl ; cin>>deg ; if(deg<0) cout<<"go learn ur textbook"<<endl ; if(deg>=0) { cout<<"give the value of the coefficients"<<endl ; for (j=0;j<=deg;j++) cin>>a[j] ; cout<<"give the value x"<<endl ; cin>>x ; ans = power(a,deg,x); cout<<"the value of p("<<x<<") = "<<ans <<endl ; } float b[size],sum[size],mult[size],y ; for(j=0;j<=size-1;j++) b[j] = sum[j] = mult[j] = 0 ; int dega,degb ; dega = deg ; /*cout<<"give the value of the coefficients"<<endl ; for (j=0;j<=dega;j++) cin>>a[j]; */ cout<<" give in the degree of poly b"<<endl ; cin>>degb ; cout<<"enter the values of the coefficient of polynomialb"<<endl ; for(j=0;j<=degb;j++) cin>>b[j] ; cout<<"give the value to be substituted in polynomialb"<<endl ; cin>>y ; ans = power(b,degb,y) ; cout<<"the value of f("<<y<<") ="<<ans<< endl ; cout<<"the value of f("<<x<<") ="<<power(b,degb,x)<<endl ; string decision ; cout<<"to you want to add or multiply a and b(type a or m) "<<endl ; cin>>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("<<x<<") +f("<<x<<") ="<<ans<<endl ;} if(degb>dega) {ans = power(sum,degb,x) ; cout<<"the answer after addition of p("<<x<<") +f("<<x<<") ="<<ans<<endl ; }} if (decision=="m") //{polymult(a,dega,b,degb,mult); //if (dega>=degb) {ans= power(a,dega,x)*power(b,degb,y) ; //cout<<"the answer of multiplication"<<ans<<endl ;} //if (degb>dega) //{ ans = power(mult,degb,x) ; cout<<"the answer after multiplication of p("<<x<<") *f("<<y<<") ="<<ans<<endl ;} return 0 ;}

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=870


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review