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*/";
}

Output:


Comments

Popular posts from this blog

To implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.