Answer to Question #4711 in C++ for Rajveer

Question #4711
Write a C++ programme to calculate the value of function f(x)=x2+1.5x+5/x-3 for x=-10to 10, x should take values -10,-8,-6,....,6,8,10
1
Expert's answer
2011-10-20T08:47:52-0400
# include <iostream>
# include <cmath>

using namespace std;

int func()
{
int x;
double y = 0;
cout<<"Enter x, x [-10,10]: ";
cin>>x;
if (x < -10 || x > 10 || x == 0 || x/2 == 0)//it's for all numbers that don't meet requirements of the program
{
& cout<<"You've entered wrong number"<<endl;
& return -1;
}
else
{
y = x*x + 1.5*x + (double)5/x - 3 ;//our function
}
cout<<"f(x) = "<<y<<endl;
return y;
}
int main()
{
func();
system ("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS