Wednesday, 15 April 2020

C++ Program - Check Number is Positive or Negative

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

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
 int a;
 cout<<"Enter any non-zero Number : ";
 cin>>a;
 (a>0)?cout<<"Number is positive":cout<<"Number is negative";
 return 0;
}

Screenshot:
 

No comments:

Post a Comment