Write a program to calculate the value of f(x) if u r given that f(x) =x+1, x<1
3x^2-x, x>1
10-x, x=1
#include<iostream>
using namespace std;
int main()
{
double x;
char choice;
do
{
cout<<"\nDo you want to calculate f(x) [Y/N]: ";
cin>>choice;
if(choice=='n'||choice=='N')break;
cout<<"Please, enter a value of x: ";
cin>>x;
if(x<1)
cout<<"f(x) = "<<x+1;
else if(x>1)
cout<<"f(x) = "<<3*x*x-x;
else if(x==1)
cout<<"f(x) = "<<10-x;
}while(true);
}
Comments
Leave a comment