如何使用按位运算符连接 2 个数字,同时保持变量的初始值不变?
How to concatenate 2 numbers using bit-wise operator, leaving initial values of variables intact?
I can not use sprintf, or any other function that puts everything together in a string n, I can not really use any libc function, it's part of a challenge I'm trying to solve
鉴于:
int x=5;
int y=2;
预期输出:
res = 52;
这是一种可能的解决方案:
#include <stdio.h>
int main()
{
int x= 342;
int y= 224;
int aux = y;
while( aux ) {
aux /= 10;
x*= 10;
}
x+= y;
printf("x= %d\r\n", x); // prints 342224
}
I can not use sprintf, or any other function that puts everything together in a string n, I can not really use any libc function, it's part of a challenge I'm trying to solve
鉴于:
int x=5;
int y=2;
预期输出:
res = 52;
这是一种可能的解决方案:
#include <stdio.h>
int main()
{
int x= 342;
int y= 224;
int aux = y;
while( aux ) {
aux /= 10;
x*= 10;
}
x+= y;
printf("x= %d\r\n", x); // prints 342224
}