All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Single Line Expression (Posted on 2008-01-27) Difficulty: 1 of 5
Give a single line "C type" expression to evaluate (-1)k using only +,-,* and % operators.

See The Solution Submitted by Praneeth    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Solution | Comment 1 of 6
1-k%2*2

Due to operator precedence, the order of evaluation is %, *, -; so no parentheses are necessary. (Both % and * have the same precedence, so % is evaluated first because it is to the left of *.)

Edited on January 27, 2008, 11:43 am
  Posted by Kurious on 2008-01-27 11:36:52

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
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:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information