0
Can i use conditional operator to check a number is +ve or - ve in c++????
Please answer
4 Antworten
+ 18
yes, U can use conditional operators here :
● note : zero is not positive, nor negative
//so we need to check for zero also :
(n==0 ? "zero" : n<0 ? "negative" : "positive")
//use above expression in cout statement
+ 15
Safal Kumar Sahgal
● take input of number [use variable n]
● in cout statement, just paste above expression written in above answer
// only that much, try once ☺👍
+ 1
Please kya aap code bana kar bata sakte ho sir??
I am just new in progrmming.
0
{
int n;
cout <<"Enter a Number";
cin>>n;
cout<<(n==0? "Zero" : n <0? "negative" : "positive")
return 0;
}
Sir isme result no output aata hai.