I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

This is for making computation faster in C++

Delta\′s Photo
1 Aug 05, 11:26AM
(1 reply)
This is for making computation faster in C++
Well i think that when ever needed we can make multiplications faster and divisions also by suing shifting instead of using the mul. So let us consider for the 3*k+1 problem in computer science. It says

1)Ask user for a number K 2)if K is even K<-K/2 else K<-3*K+1 4)Check if K is equal to 1 Else go to step 2 again Here the 3*K+1 and K/2 can be performed in the following manner:

K+=(K<<1)+1;//This is 3*K+1 and K=K>>1;//This is K/2
john\′s Photo
11 Nov 05, 12:59AM
btw Most compilers will automatically convert k/2 into k>>1. So it often better to leave it in the more readable form. 8)
Currently you need to be logged in to leave a message.