首页 > 试题广场 >

编写函数实现两数交换(指针方式)

[编程题]编写函数实现两数交换(指针方式)
  • 热度指数:15289 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
编写一个函数,实现两个整数的交换,要求采用指针的方式实现。

输入描述:
键盘输入2个整数 m 和 n


输出描述:
输出交换后m 和 n 的值,中间使用空格隔开
示例1

输入

2
3

输出

3 2
头像 牛客395651087号
发表于 2021-11-04 18:21:32
using namespace std; // write your code here...... void swap(int *p, int *q); void swapp(int &a, int &b); int main() { int m, n; ci 展开全文
头像 力纳克斯
发表于 2022-05-29 12:06:21
#include <stdio.h> int main(void) {     int m,n,temp;     scanf("%d %d",&m,& 展开全文
头像 2104060427张喜海
发表于 2022-02-19 18:41:10
#include using namespace std; // write your code here...... void lhy(int * p1,int * p2) { int temp =*p1; *p1=*p2; *p2=temp; } int main() { int m, n; 展开全文
头像 wydxry
发表于 2021-11-08 18:37:22
#include <iostream> #include <bits/stdc++.h> using namespace std; // write your code here...... int main() { int m, n; cin > 展开全文
头像 牛客659424139号
发表于 2022-04-14 21:19:34
江边菜鸟 #include using namespace std; // write your code here...... void swap(int *p, int *q); int main() { int m, n; cin >> m; cin >> n; / 展开全文
头像 不服输的小野猪
发表于 2023-03-04 16:09:14
#include <stdio.h> void swap(int * p,int * q) { int t; t=*p; *p=*q; *q=t; } int main() { int m; int n; scanf("%d%d" 展开全文
头像 bsdn_n
发表于 2022-08-08 09:35:06
#include<stdio.h>//使用了指针和二重指针哦,欢迎大佬萌新点评改正 int main() {     int m,n;     scanf("%d%d",&m,&a 展开全文
头像 牛场主
发表于 2023-05-18 19:48:04
#include <iostream> #include <utility> using namespace std; // write your code here...... int temp; int swap (int *m, int *n) { tem 展开全文
头像 宇航员.
发表于 2022-03-30 20:12:43
#include using namespace std; // write your code here void swap(int *a,int *b)//形参定义为指向a,b的指针 { //定义一个参数来交换a,b所指向的数值 int t=*a; *a=*b; *b=t; } int ma 展开全文
头像 诗奕
发表于 2024-01-14 17:20:54
#include<stdio.h> void swap(int *a,int *b) { int temp=*a; *a=*b; *b=temp; } int main () { int m,n=0; scanf("%d %d" 展开全文

问题信息

难度:
42条回答 898浏览

热门推荐

通过挑战的用户

查看代码