|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
题目和要求如图,但是小甲鱼给的答案没按照题目的来,求大佬帮忙更改一下小甲鱼的答案,我自己按着题目的代码敲完之后弄了好半天没有输出正确的结果
- #include <stdio.h>
- int main(void)
- {
- int a, b, c, t;
- int *pa, *pb, *pc;
-
- printf("请输入三个数:");
- scanf("%d%d%d", &a, &b, &c);
-
- pa = &a;
- pb = &b;
- pc = &c;
-
- if (a > b)
- {
- t = *pa;
- *pa = *pb;
- *pb = t;
- }
-
- if (a > c)
- {
- t = *pa;
- *pa = *pc;
- *pc = t;
- }
-
- if (b > c)
- {
- t = *pb;
- *pb = *pc;
- *pc = t;
- }
-
- printf("%d <= %d <= %d\n", *pa, *pb, *pc);
- printf("%d <= %d <= %d\n", a, b, c);
-
- return 0;
- }
复制代码
这个题目我记得之前有人发过。
题目的目的是让你学习指针的用法,改变指针的指向,不影响原来的变量
- #include <stdio.h>
- int main(void)
- {
- int a, b, c, t;
- int *pa, *pb, *pc, *temp;
-
- printf("请输入三个数:");
- scanf("%d%d%d", &a, &b, &c);
-
- pa = &a;
- pb = &b;
- pc = &c;
-
- if (a > b)
- {
- temp = pa;
- pa = pb;
- pb = temp;
- }
-
- if (a > c)
- {
- temp = pa;
- pa = pc;
- pc = temp;
- }
-
- if (b > c)
- {
- temp = pb;
- pb = pc;
- pc = temp;
- }
-
- printf("%d <= %d <= %d\n", *pa, *pb, *pc);
- //printf("%d <= %d <= %d\n", a, b, c);
-
- return 0;
- }
复制代码
|
|