#include<stdio.h>
#include<stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
int main()
{
float a, b, c,t;
printf("please enter three figuer");
scanf_s("%f,%f,%f", &a, &b, &c);
if (a > b)
{
t = a; a = b; b = t;
}
if (a > c)
{
t = a; a = c; c = t;
}
if (b > c)
{
t = b; b = c; c = t;
}
printf( " %f,%f,%f\n",a,b,c);
return 0;
}
题目是,输入三个数按从小到大顺序输出
//输入三个字符串,按由小到大的 顺序输出,用指针来实现
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define M 5
int main()
{
char a[M], b[M], c[M];
char *p, *q, *t;
char x[M];
printf("请输入三个字符串:\n");
gets(a);
gets(b);
gets(c);
p = a; // abc
q = b; // agf
t = c; // ccc
// printf("输出%d\n", strcmp(p, q)); // 输出-1 说明 p比q小
// printf("strcmp(q,p) 输出%d\n", strcmp(q,p)); // 输出1 说明 q比p 大
if ((strcmp(p, q)) > 0) // p 比 q 大,交换 pq的值,让小的放前面
{
strcpy(x, p); // 将p的值覆盖到x里面,
strcpy(p, q); // 将q的值覆盖到p
strcpy(q, x); // 将x的值覆盖到q
}
if ((strcmp(p, t)) > 0) // p > t ? 同上,x相当于 temp 辅助交换
{
strcpy(x, p);
strcpy(p, t);
strcpy(t, x);
}
if ((strcmp(q, t)) > 0) // q > t
{
strcpy(x, q);
strcpy(q, t);
strcpy(t, x);
}
printf("输出由小到大排序好的三个字符串:%s\t%s\t%s\n", p, q, t);
return 0;
}
result:
请输入三个字符串:
ccc
abf
acb
输出由小到大排序好的三个字符串:abf acb ccc
你怎么输入的,发出来看看
scanf原样输入,你输入的数要逗号分隔呀
输入的三个值之间要用逗号分隔