📄 multiply.cpp
字号:
#include <iostream.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
unsigned long multiply(unsigned short xp1, unsigned short xp2)
{
unsigned long x[16];
unsigned long sumx;
unsigned int i;
sumx = 0;
for(i=0;i<16;i++){
x[i]=(unsigned long)xp1;
}
for(i=0;i<16;i++){
if(xp2&((unsigned short)1<<(15-i))){
xp2-=(unsigned short)1<<(15-i);
x[15-i]<<=(15-i);
}
else{
x[15-i]=0;
}
}
for(i=0;i<16;i++){
sumx+=x[i];
}
return sumx;
}
unsigned long Mul(unsigned int x1, unsigned int x2)
{
unsigned long sum;
unsigned short p1,p2;
if(x1>65535||x2>65535||x1<0||x2<0){
cout<<"ERRO: Input out of scope!"<<endl;
exit( 1 );
}
p1=(unsigned short)x1;
p2=(unsigned short)x2;
if(0==p1||0==p2){
return 0;
}
if(p1>p2){
sum=multiply(p1,p2);
}
else{
sum=multiply(p2,p1);
}
return sum;
}
int main(int argc, char *argv[])
{
unsigned int x1, x2;
cout<<"Arguements number:"<<argc<<"(Including the name of the application function)"<<endl;
cout<<"Arguements are bellow:"<<endl;
for(int index=0;index<argc;index++){
cout<<argv[index]<<endl;
}
for(;;){
cout<<"Input x1 and x2 (0~65535)"<<endl;
scanf("%ld",&x1);
scanf("%ld",&x2);
cout<<"result is:"<<Mul(x1,x2)<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -