1.判断偶数
void panduan(int a)
{
if(a%2 == 0)
{
cout<<"True"<<endl;
}
else{
cout<<"False"<<endl;
}
}
3.迭代法
void multiplication(int a,int b)
{
while(a>1)
{
int r = (a-1) * b;
b = r;
a--;
}
cout<<b<<endl;
}
选做:
void panduan(int a)
{
int n = 0,r;
int b;
if(a == 1)
{
cout<<"这个数是2的0次方";
}
if(a!=1)
{
while(a != 1)
{
b = a % 2;
a = a / 2;
n++;
r = n;
if(b==1)
{
break;
}
if(b==0)
{
continue;
}
}
if((a==1)&&(b==0))
{
cout<<"这个数是2的"<<r<<"次方";
}
else
{
cout<<"这个数不是2的"<<a<<"次方";
}
}
}