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 create an html page with frames and frameset

1. Write a program to insert a new element at end as well as at a given position in an array in Java

1. To familiarize with network devices like switch, hub, routers and bridges in LaTex