注册 登录
编程论坛 C语言论坛

1.用函数实现两个整数值的交换

C菜鸟是我 发布于 2020-05-25 11:30, 2183 次点击
#include<stdio.h>
int main()
{int fun (int *p1,int *p2);
int a,b;
int *p1,*p2;
scanf("%d,%d",&a,&b);
p1=&a;p2=&b;
fun(p1,p2);
printf("%d,%d"*p1,*p2);
}
int fun(int *p1,int *p2)
{int a,b;
    p1=&b;
p2=&a;
}
有什么错误,怎样改正
5 回复
#2
吹水佬2020-05-25 11:43
int fun(int *p1,int *p2)
{
    int a;
    a = *p1;
    *p1 = *p2;
    *p2 = a;
}
#3
C菜鸟是我2020-05-25 14:53
不对啊,前面还有错误
#4
C菜鸟是我2020-05-25 15:58
#include<stdio.h>
int main()
{void swap (int *p1,int *p2);
int a,b;
int *pointer1,*pointer2;
scanf("%d,%d",&a,&b);
pointer1=&a;
pointer2=&b;
swap(pointer1,pointer2);
printf("%d,%d"a,b);
}
void swap(int *p1,int *p2)
{int a ;
  a=*p1;
  *p1=*p2;
  *p2=a;
}
这是修改之后的,还是有错误,求指教
C:\Users\lenovo\Desktop\自动化\1.c(10) : error C2146: syntax error : missing ')' before identifier 'a'
C:\Users\lenovo\Desktop\自动化\1.c(10) : error C2059: syntax error : ')'
执行 cl.exe 时出错.
#5
fulltimelink2020-05-25 16:04
回复 4楼 C菜鸟是我
错误提示的很明显了,第10行
printf  format和后面的参数之间要用逗号隔开
printf("%d,%d",a,b);
#6
C菜鸟是我2020-05-25 18:07
谢谢
1