Write a program that will read the value of x and evaluate the following function: Y= 2 for x>0, Y=0 for x=0 Use nested statements with the conditional control statement.
#include<iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter x\n";
cin>>x;
if(x>0)
{
cout<<"x is "<<x<<" Y is 2\n\n"<<endl;
}
else if(x==0)
{
cout<<"x is "<<x<<" Y is 0\n\n"<<endl;
}
else
{
cout<<"x is negative So is Y\n\n"<<endl;
}
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}
using namespace std;
int main()
{
int x;
cout<<"Enter x\n";
cin>>x;
if(x>0)
{
cout<<"x is "<<x<<" Y is 2\n\n"<<endl;
}
else if(x==0)
{
cout<<"x is "<<x<<" Y is 0\n\n"<<endl;
}
else
{
cout<<"x is negative So is Y\n\n"<<endl;
}
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}
Comments
Post a Comment