网站制作学习网Linux→正文:C实现交换两个变量
字体:

C实现交换两个变量

Linux 2015/2/21 13:52:37  点击:不统计

http://%77%77%77%2E%66网站制作%6F学习网%72%61%73%70%2E%63%6E
 采用第三个变量形式

#include<stdio.h>
int test1_8(){
    int a,b,t;
    scanf("%d%d",&a,&b);
    t = a;
    a = b;
    b = t;
    printf("a = %d b = %d",a,b);
    return 0;
}
 
不用第三个变量实现数据互换
#include<stdio.h>
int test1_9(){
    int a,b;
    scanf("%d%d",&a,&b);
    a = a+b;
    b = a - b;
    a = a - b;
    printf("a = %d,b=%d",a,b);
    return 0;
}

#include<stdio.h>
int main(){
    //test1_8();
    test1_9();
}
 

forasp.cn

·上一篇:mysql5.6配置,更改datadir >>    ·下一篇:linux shell删除7天前的文件 >>
推荐文章
最新文章