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

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN