Home > Algorithms
Single Line Expression (Posted on 2008-01-27) |
|
Give a single line "C type" expression to evaluate (-1)k using only +,-,* and % operators.
|
Submitted by Praneeth
|
Rating: 5.0000 (1 votes)
|
|
Solution:
|
(Hide)
|
Apologies for not mentioning that k is an integer.
Answer:
(-1)k=1-2*(k%2); |
Comments: (
You must be logged in to post comments.)
|
|
Please log in:
Forums (1)
Newest Problems
Random Problem
FAQ |
About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On
Chatterbox:
|