cout << "It's " << (n%2)?"odd":"even" << "!" << endl;
Btw, &1 will only work on 2's complement and sign-magnitude computers, it will be backward for negative numbers on 1's complement machines.
[edited by - Magmai Kai Holmlor on March 8, 2003 8:05:49 PM]
c++ - How to read a even or odd from a number?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Hmm.. that''s true.. So, on 1s complement computers, would it still work for positive numbers?
So then you could just use it if you''re working with unsigned #s, maybe.
So then you could just use it if you''re working with unsigned #s, maybe.
quote: Original post by Magmai Kai Holmlor
cout << "It''s " << (n%2)?"odd":"even" << "!" << endl;
Btw, &1 will only work on 2''s complement and sign-magnitude computers, it will be backward for negative numbers on 1''s complement machines.
''Course, how many people are still using a 1''s compliment machine? The only one I can think of are the Unisys 2200 mainframes, and I doubt many of us get to use them these days...
If I had my way, I''d have all of you shot! codeka.com - Just click it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement