用C語言寫兩個正整數相加的函數,只能用邏輯運算符,
題目:
用C語言寫兩個正整數相加的函數,只能用邏輯運算符,
就是寫一個unsigned int addr(unsigned int,unsigned int);不能用加減號
解答:
unsigned int addr(unsigned int num1,unsigned int num2)
{
unsigned int sum=0;
unsigned int num3=0;
unsigned int num4=0;
while((num1&num2)>0)
{
num3=num1^num2;
num4=num1&num2;
num1=num3;
num2=num4
添加新評論