输入3个整数按由大到小的顺序输出。要求用指针方法处理平台编译Sort2c然后链接相关程序库并生成Sort2exe;平台运行Sort2exe并以标准方式提供测试输入;平台获取Sort2exe的输出然后将其与预测输出对比如果一致则测试通过;否则测试失败。 以下是平台对Sort2c的测试样例:
#include <stdio.h>
void sort(int* a, int* b, int* c) {
int temp;
if (*a < *b) {
temp = *a;
*a = *b;
*b = temp;
}
if (*b < *c) {
temp = *b;
*b = *c;
*c = temp;
}
if (*a < *b) {
temp = *a;
*a = *b;
*b = temp;
}
}
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
sort(&a, &b, &c);
printf("%d %d %d\n", a, b, c);
return 0;
}
测试样例输入:
3 5 2
预测输出:
5 3 2
原文地址: http://www.cveoy.top/t/topic/i1YB 著作权归作者所有。请勿转载和采集!