输入四个整数,按照从小到大排列。
#pragma warning(disable:4996)
#include<stdio.h>
int main(void)
{
long long A[10];
long long B[10];
int count, count_outside, count_inside,geted;
geted = 0;
printf("Please enter four integers:");
for (count = 0; count <= 3; count++)
scanf("%lld", &A[count]);
for(count_outside=0;count_outside <= 3;count_outside++)
{
for(count_inside=0;count_inside <= 3;count_inside++)
{
for (count = 1; (count_inside + count) <= 3;count ++)
{
if (A[count_inside] >= A[count_inside + count])
geted = count_inside + count;
}
}
B[count_outside] = A[geted];
A[geted] = 100000000+count_outside;
}
for (count = 0; count <= 3; count++)
printf("%lld ",B[count]);
return 0;
}
Please enter to integers:1 2 3 4
1 4 3 100000001
D:\AHPU教学\P99-5\x64\Debug\P99-5.exe (进程 10768)已退出,代码为 0。
按任意键关闭此窗口
想用两个数组去解,先把四个整数放进数组A中,然后找到最小的值,记下其地址,然后赋给数组B的第一个值,再将该地址的数据赋值极大,依次循环再找第二小的,赋给B的第二个值
最后按顺序输出数组B的值。