1.输入3个整数,按由小到大的顺序输出
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void swap(int* p1, int* p2) {
int temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main() {
int a, b, c;
int* p, * q, * r;
scanf("%d %d %d", &a, &b, &c);
p = &a;
q = &b;
r = &c;
if (*p > *q) swap(p, q);
if (*p > *r)swap(p, r);
if (*q > *r)swap(q, r);
printf("%d<%d<%d\n", *p, *q, *r);
return 0;
}
2.输入3个字符串,按由小到大的顺序输出
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
void swap(char* p, char* q) {
char temp[20];
strcpy(temp, p);
strcpy(p, q);
strcpy(q, temp);
}
int main() {
char str1[100], str2[100], str3[100];
printf("请输入字符串:\n");
gets_s(str1);
gets_s(str2);
gets_s(str3);
if (strcmp(str1, str2)>0) swap(str1, str2);