In: Computer Science
Problems
create a C++ program that will do the followings
- define 3 double variables x, y, z
- calculate the value of y as the following formula: y = 2*x*x+4*x+5 and print x and y;
- assign a new value to x: x=5.6
- calculate the value of z as the following formula
z = (y*y)/4 + (x*x)/5
- print x, y,x
CODE:
#include <iostream>
using namespace std;
int main()
{
double x;
double y;
double z;
cout<<"Enter a floating point value: ";
cin>>x;
cout<<x<<" is stored into x\n";
//y=2*x*x+4*x+5
y = (2.0*x*x)+(4.0*x)+5.0;
cout<<"Y is calculated as per this formula
<y=2*x*x+4*x+5>\n";
cout<<"And the value of Y is = "<<y<<"\n";
//z=(y*y)/4+(x*x)/5
cout<<"The value of x is changed to x=5.6\n";
x=5.6;
cout<<"Now Z is calculated as per this formula
<z=(y*y)/4+(x*x)/5>\n";
z=(y*y)/4+(x*x)/5;
cout<<"And the value of z is = "<<z;;
return 0;
}
OUTPUT: