c语言用指针方法输入3个数a,b,c,按大小顺序输出,输出结果只能输出最小的那个其他两个有错求修改#include "stdio.h"#include "conio.h"main(){int n1,n2,n3;int *pointer1,*pointer2,*pointer3;printf("please input 3 number:n
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 18:31:20
c语言用指针方法输入3个数a,b,c,按大小顺序输出,输出结果只能输出最小的那个其他两个有错求修改#include "stdio.h"#include "conio.h"main(){int n1,n2,n3;int *pointer1,*pointer2,*pointer3;printf("please input 3 number:n
c语言用指针方法输入3个数a,b,c,按大小顺序输出,输出结果只能输出最小的那个其他两个有错求修改
#include "stdio.h"
#include "conio.h"
main()
{
int n1,n2,n3;
int *pointer1,*pointer2,*pointer3;
printf("please input 3 number:n1,n2,n3:");
scanf("%d,%d,%d",&n1,&n2,&n3);
pointer1=&n1;
pointer2=&n2;
pointer3=&n3;
if(n1>n2) swap(pointer1,pointer2);
if(n1>n3) swap(pointer1,pointer3);
if(n2>n3) swap(pointer2,pointer3);
printf("the sorted numbers are:%d,%d,%d\n",n1,n2,n3);
getch();
}
swap(p1,p2)
int *p1,*p2;
{
int p;
p=*p1;*p1=*p2;*p2=p;
}
c语言用指针方法输入3个数a,b,c,按大小顺序输出,输出结果只能输出最小的那个其他两个有错求修改#include "stdio.h"#include "conio.h"main(){int n1,n2,n3;int *pointer1,*pointer2,*pointer3;printf("please input 3 number:n
#include "stdio.h"
#include "conio.h"
swap(int *p1,int *p2) /*放在前面,不然要声明*/
{ /*你原来定义的int *p1,*p2;放在函数形参里面*/
int p;
p=*p1;*p1=*p2;*p2=p;
}
main()
{
int n1,n2,n3;
int *pointer1,*pointer2,*pointer3;
printf("please input 3 number:n1,n2,n3:");
scanf("%d,%d,%d",&n1,&n2,&n3);
pointer1=&n1;
pointer2=&n2;
pointer3=&n3;
if(n1>n2) swap(pointer1,pointer2);
if(n1>n3) swap(pointer1,pointer3);
if(n2>n3) swap(pointer2,pointer3);
printf("the sorted numbers are:%d,%d,%d\n",n1,n2,n3);
getch();
}