题目:输入3个数a,b,c,按大小顺序输出。(函数方法)
程序:
#include <stdio.h>
void swap(int *p1,int *p2);
int main(void)
{
int a,b,c;
printf("Please enter three number:\n");
scanf("%d,%d,%d",&a,&b,&c);
printf("The early elements are:%d,%d,%d\n",a,b,c);
if(a > b) swap(&a,&b);
if(a > c) swap(&a,&c);
if(b > c) swap(&b,&c);
printf("The last elements are:%d,%d,%d\n",a,b,c);
return 0;
}
void swap(int *p1,int *p2)
{
int p;
p = *p1;
*p1 = *p2;
*p2 = p;
}
输出样例
打卡7.25
网友评论