```
//how to make it for decimal division,eg:x+=0.0001
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
double temp;
double x;
double valueArray[10];//max constants
int found=0;
int index,n,prntcnt;
cout<<"enter the value for n: ";
cin>>n;
if (n==1)
{cout<<"For ALL x equation is balanced"<<endl;
return 0;}
for (prntcnt=n-1;prntcnt>=0;prntcnt--){
cout<<"(A"<<n-prntcnt<<")";
if (prntcnt!=0)
cout<<'x'<<prntcnt<<" + ";
else
cout<<" = 0";
}
for (index=0; index<n;index++)
{
cout<<"\n\n";
cout<<"enter a value for (A"<<index+1<<"): ";
cin>>valueArray[index];
}
for (x=0;found!=n-1&&x<250;x+=0.01) {
for (temp=0,--index;index>=0;index--)
temp=temp+valueArray[index]*pow(x,n-1-index);
if (temp==0) //include "||fabs(temp)<1e-5)" to the boolean condition to get the answer
cout<<endl<<++found<<" ROOT is "<<x;
index=n;
}
if (found!=n-1){
for (x=-0.01;found!=n-1&&x>-250;x-=0.01) {
for (temp=0,index--;index>=0;index--)
temp=temp+valueArray[index]*pow(x,n-1-index);
if (temp==0||fabs(temp)<1e-5)
cout<<endl<<++found<<" ROOT is "<<x<<endl;
index=n;
}
}
if (found==0)
cout<<"NOT FOUND!";
else
{for ( ;found<n-1;)
cout<<++found<<" ROOT is one of the ABOVE"<<endl;
}
cout<<endl;
return 0;
}
/*
the case is when u give the equation 2x-1=0 it says "not found". but if u include the above
given st. to the if's boolean condition it will give the correct root without giving an error.
note that this is bcoz; when x is given a value which will make 2x-1 closer to zero the variable
temp is getting a very very small value but not ZERO!*/
```