ass
unknown
plain_text
a year ago
984 B
7
Indexable
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
double fun(double x, vector<int> p, vector<int> c){
double sum=0;
while(!p.empty()){
double po=p.back();
p.pop_back();
double co=c.back();
c.pop_back();
double k=co*pow(x,po);
sum=sum+k;
}
return sum;
}
int main(){
vector<int> coeff;
vector<int> power;
int a,b,c;
while(true){
cout<<"Give power and coeffiecent polynomial as input. 1 to contiue and 0 to end";
cin>>c;
if(c==0){
break;
}
cin>>a;
cin>>b;
power.push_back(a);
coeff.push_back(b);
}
cout<<"give range and step length";
double lower,upper,len;
cin>>lower;
cin>>upper;
cin>>len;
double max=-99999999;
double min=99999999;
double k=0;
double q=lower;
for(int i=1; q<=upper ; i++ ){
k=fun(q,power,coeff);
if(k>max){
max=k;
}
if(k<min){
min=k;
}
q=lower+len*i;
}
cout<<"Min and max value of x is : "<<min<<" AND "<<max;
return 0;
}Editor is loading...
Leave a Comment