```
//PROGRAM TO FIND DERIVATIVE(FIRST AND SECOND)OF POLYNOMIAL FUNCTIONS
#include<iostream.h>
#include<conio.h>
void main()
{
int i,d,coeff[100],degree[100];
clrscr();
cout<<"\nEnter the degree of the polynomial : ";
cin>>d;
for(i=d;i>=0;i--)
{ if(i>1)
{
degree[i]=i;
cout<<"\nEnter the coefficient of x^"<<degree[i]<<" (with sign) : ";
cin>>coeff[i];
}
else if(i==1)
{
degree[i]=i;
cout<<"\nEnter the coefficient of x (with sign) : ";
cin>>coeff[i];
}
else
{
degree[0]=0;
cout<<"\nEnter the constant term (if any) : ";
cin>>coeff[0];
}
}
clrscr();
cout<<"\n Entered polynomial function , f (x)=";
for(i=d;i>=0;i--)
{
if(coeff[i]>0&°ree[i]!=1)
{
if(degree[i])
cout<<"+"<<coeff[i]<<"x^"<<degree[i];
else
cout<<"+"<<coeff[0];
}
else if(coeff[i]<0&°ree[i]!=1)
{
if(degree[i])
cout<<coeff[i]<<"x^"<<degree[i];
else
cout<<coeff[0];
}
else if(coeff[i]!=0&°ree[i]==1)
{
if(coeff[i]>0)
cout<<"+"<<coeff[i]<<"x";
else
cout<<coeff[i]<<"x";
}
}
getch();
for(i=d;i>=0;i--)
{
coeff[i]*=degree[i];
degree[i]-=1;
}
cout<<"\n First derivative of function , f'(x)=";
for(i=d;i>=0;i--)
{
if(coeff[i]>0&°ree[i]!=1)
{
if(degree[i])
cout<<"+"<<coeff[i]<<"x^"<<degree[i];
else
cout<<"+"<<coeff[i];
}
else if(coeff[i]<0&°ree[i]!=1)
{
if(degree[i])
cout<<coeff[i]<<"x^"<<degree[i];
else
cout<<coeff[i];
}
else if(coeff[i]!=0&°ree[i]==1)
{
if(coeff[i]>0)
cout<<"+"<<coeff[i]<<"x";
else
cout<<coeff[i]<<"x";
}
}
getch();
for(i=d;i>=0;i--)
{
coeff[i]*=degree[i];
degree[i]-=1;
}
cout<<"\n Second derivative of function , f\"(x)=";
for(i=d;i>=0;i--)
{
if(coeff[i]>0&°ree[i]!=1)
{
if(degree[i])
cout<<"+"<<coeff[i]<<"x^"<<degree[i];
else
cout<<"+"<<coeff[i];
}
else if(coeff[i]<0&°ree[i]!=1)
{
if(degree[i])
cout<<coeff[i]<<"x^"<<degree[i];
else
cout<<coeff[i];
}
else if(coeff[i]!=0&°ree[i]==1)
{
if(coeff[i]>0)
cout<<"+"<<coeff[i]<<"x";
else
cout<<coeff[i]<<"x";
}
}
getch();
}
```

nitinmbhanu
-3
Newbie Poster

mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.