在不引入第三个变量的前提下将两个变量交换 1e9 次,我选用了位运算的方式进行交换。
    在交换1e9次之后,所使用的时间约为3秒,在不同电脑之间有所差别

    1. #include<stdlib.h>
    2. #include<stdio.h>
    3. #include<time.h>
    4. void swap_us(int a,int b){
    5. a=a^b;
    6. b=a^b;
    7. a=a^b;
    8. }
    9. int main(){
    10. int a,b;
    11. scanf("%d %d",&a,&b);
    12. double dur;
    13. clock_t start, end;
    14. start = clock();
    15. for(int i=0;i<=1e9;i++){
    16. swap_us(a,b);
    17. }
    18. end = clock();
    19. dur = (double)(end - start);
    20. printf("%d %d",a,b);
    21. printf("Use Time:%f\n", (dur / CLOCKS_PER_SEC));
    22. return 0;
    23. }