This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15631|Reply: 0

[C] Pointer method Input 3 integers and output them in order from smallest to largest

[Copy link]
Posted on 12/15/2015 2:27:04 PM | | |
//输入3个整数,按由小到大的顺序输出
#include "stdafx.h"
#include "stdio.h"
int main()
{void paixu(int *p1,int *p2);
int n1,n2,n3;
int *p1,*p2,*p3;
printf("input three integer n1,n2,n3:");
scanf("%d,%d,%d",&n1,&n2,&n3);
p1=&n1;
p2=&n2;
p3=&n3;
if(n1>n2) paixu(p1,p2);
if(n1>n3) paixu(p1,p3);
if(n2>n3) paixu(p2,p3);
printf("now,the order is:%d,%d,%d\n",n1,n2,n3); They are all to be separated
return 0;
}
void paixu(int *p1,int *p2)
{int p;
p=*p1; *p1=*p2; *p2=p;
}






Previous:Pointer method Input 3 strings and output them in order from smallest to largest
Next:After learning the pointer for several days, what is it used for, and why does he use it?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com