您好,欢迎来到品趣旅游知识分享网。
搜索
您的当前位置:首页编写程序,输入两个整数a和b,交换它们的值,然后输出。

编写程序,输入两个整数a和b,交换它们的值,然后输出。

来源:品趣旅游知识分享网

撰写人——软工二班——陈喜平
题目描述
编写程序,输入两个整数a和b,交换它们的值,然后输出。

输入
两个整数a和b
输出
a、b交换后的值。注意:两个数之间有1个空格,输出后换行。
样例输入
3 5
样例输出
5 3
提示
来源
hnldyhy

方法一

#include<stdio.h>
#include<math.h>
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<stdio.h>
#include<stdlib.h>
#include<math.h>
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 © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务