//Check No is negative,positive Or Zero
int n=10;
if(n<0)
{
cout<<"Negative\n";
}
else if(n>0)
{
cout<<"Positive\n";
}
else
{
cout<<"Zero\n";
}
This code is firsts checking the condition that whether our No is negative if it is negative then It will executes first part.You can use any no instead of 'n' or assign any value to 'n'. if first Condition is not true then our second part is going to check if our No is greater then zero then our second part is executed and print "positive" and If No is neither Positive Nor negative then our no is definitely zero so our Else part is going to executes and prints "Zero".
No comments:
Post a Comment