[关闭]
@chawuciren 2019-09-08T13:19:50.000000Z 字数 224 阅读 419

CINTA作业1-编程题(Multiplication)

CINTA


  1. /*
  2. * Input: two integer(a and b)
  3. * Output: a*b
  4. * Method: iterative method
  5. */
  6. int Multiplication(int a,int b){
  7. int res=0;
  8. do{
  9. int p=b&1;//存放这一位
  10. b=b>>1;//b右移一位,下一次迭代就可以取下一位
  11. if(p==1)
  12. res+=a;
  13. a<<=1;
  14. }while(b!=0);
  15. return res;
  16. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注