编写程序,输入两个整数a和b,交换它们的值,然后输出。 |
您所在的位置:网站首页 › 用c语言将两个数交换成一个数 › 编写程序,输入两个整数a和b,交换它们的值,然后输出。 |
撰写人——软工二班——陈喜平 题目描述 编写程序,输入两个整数a和b,交换它们的值,然后输出。 输入 两个整数a和b 输出 a、b交换后的值。注意:两个数之间有1个空格,输出后换行。 样例输入 3 5 样例输出 5 3 提示 来源 hnldyhy 方法一 #include #include int main(){ int a,b,c; scanf("%d%d",&a,&b); c=a; a=b; b=c; printf("%d %d\n",a,b); return 0; }方法二 #include #include #include int f(int *x,int *y) { int t=*x; *x=*y; *y=t; return *x,*y; } int main() { int a,b; scanf("%d%d",&a,&b); f(&a,&b); printf("%d %d\n",a,b); return 0; } |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |