12th Class NCERT Solution Download Click Here!

X




Sunday, 13 March 2016

Write a program to check whether the given number is positive or negative (using ? : ternary operator )


#include<iostream>
using namespace std;

int main()
{
 int a;
 cout<<"Enter any non-zero Number : ";
 cin>>a;
 (a>0)?cout<<"Number is positive":cout<<"Number is negative";
 
 
 return 0;
}

OUTPUT:

SAMPLE RUN # 1
Enter any non-zero Number : 56 Number is positive
SAMPLE RUN # 2
Enter any non-zero Number : -14 Number is negative

No comments:

Post a Comment