c++乘法器的簡單實現

#include<iostream>

using namespace std;


int multi(int a,int b)
{
int tmp=0;

if(a<b){

tmp=a;

a=b;

b=tmp;

tmp=0;

}

while(b){

if(b&0x1)

  tmp+=a;

a<<=1;
b>>=1;
}
return tmp;

}

int main(){
int a,b;
while(cin>>a>>b)
cout<<multi(a,b)<<endl;
return 1;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章