How to concatenate two integers in C

后端 未结 9 1300
执念已碎
执念已碎 2020-11-29 11:27

Stack Overflow has this question answered in many other languages, but not C. So I thought I\'d ask, since I have the same issue.

How does one concatenate t

9条回答
  •  感动是毒
    2020-11-29 11:55

    here's another way to do it:

    int concat(int x, int y) {
        int temp = y;
        while (y != 0) {
            x *= 10;
            y /= 10;
        }
        return x + temp;
    }
    

    who knows what performance you'll get. just try and see..

提交回复
热议问题