+ 1

Input a number and check whether it is positive or negative??

Pls answer it

11th Jul 2016, 2:05 PM
Mohammed shibili
Mohammed shibili - avatar
10 odpowiedzi
+ 2
Include the header files int main() { float a; cin>>a; if(a>0) {cout<<"The no. u entered is positive";} else if(a==0) {cout<<"0 is an unique no.";} else {cout<<"The no. u entered is negative";} }
11th Jul 2016, 2:10 PM
Sarthak Saxena
Sarthak Saxena - avatar
+ 1
Pls check the corrections
11th Jul 2016, 2:16 PM
Sarthak Saxena
Sarthak Saxena - avatar
+ 1
Why it is float???Sathak
11th Jul 2016, 2:21 PM
Mohammed shibili
Mohammed shibili - avatar
0
is RETURN O IS NEEDED?
11th Jul 2016, 2:12 PM
Mohammed shibili
Mohammed shibili - avatar
0
No not needed
11th Jul 2016, 2:15 PM
Sarthak Saxena
Sarthak Saxena - avatar
0
😨
11th Jul 2016, 2:29 PM
Akshay AK
Akshay AK - avatar
0
it's float cuz if one enters a decimal number float data type is required . int data type will not accept decimal
11th Jul 2016, 3:19 PM
Sarthak Saxena
Sarthak Saxena - avatar
0
Every signed datatype uses the most significant bit (msb) as it's sign, and because using < or > is expensive when dealing with non integer values you could use bitwise-AND with the corresponding value. bool isNegative(double v) { unsigned long long* _v = (typeof(_v))&v; bool isNeg = *_v & ((typeof(*_v))1 << (8*sizeof(*_v) - 1)); delete _v; return isNeg; }
11th Jul 2016, 3:46 PM
Garme Kain
Garme Kain - avatar
0
ya needed it's called success full termination
11th Jul 2016, 6:42 PM
abhiram reddy
abhiram reddy - avatar
0
you can also use if(a>=0) as sometimes 0 is considered to be +ve
15th Jul 2016, 3:45 AM
Rohit Sarkar
Rohit Sarkar - avatar