0

Can i use conditional operator to check a number is +ve or - ve in c++????

Please answer

23rd Dec 2018, 12:03 PM
Safal Kumar Sahgal
Safal Kumar Sahgal - avatar
4 Respostas
+ 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
23rd Dec 2018, 12:24 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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 ☺👍
23rd Dec 2018, 3:21 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Please kya aap code bana kar bata sakte ho sir?? I am just new in progrmming.
23rd Dec 2018, 1:59 PM
Safal Kumar Sahgal
Safal Kumar Sahgal - avatar
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.
23rd Dec 2018, 3:41 PM
Safal Kumar Sahgal
Safal Kumar Sahgal - avatar