Write a program to calculate y where y 2x2 3x 1 and 0 les
Write a program to calculate y, where y = 2^x2 + 3x + 1 and 0 lessthanorequalto x lessthanorequalto 3. Assume x comes from P1 and y is output to P2. If x is outside the range, output a zero to P2.
Solution
#include<iostream>
using namespace std;
int main()
{
cout<<\"Enter the value of x:\"<<endl;
int x;
cin >> x;
if(x >= 0 && x <= 3)
{
float y = 2*x*x + 3*x + 1;
cout<<\"Output: \"<<y<<endl;
}
else //Invalid input
{
cout<<\"Output: \"<<0<<endl;
}
return 0;
}
