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.

  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.)
  Subject Author Date
SolutionPuzzle SolutionK Sengupta2022-09-12 01:09:42
re(2): Whole numbers is reasonable assumption [Spoiler]Dej Mar2008-01-29 07:03:42
Hints/Tipsre: Whole numbers is reasonable assumptionGamer2008-01-28 13:46:14
Whole numbers?Erik O.2008-01-28 09:48:32
Questionre: SolutionDej Mar2008-01-27 22:17:06
SolutionSolutionKurious2008-01-27 11:36:52
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


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