#include
using namespace std;
void sort(int *x, int *y, int *z);
int main()
{
int a, b, c, a1, b1, c1;
cout << "Please enter 3 integers:";
cin >> a >> b >> c;
a1 = a, b1 = b, c1 = c;
sort(&a1, &b1,&c1);
cout << a << " " << b << " " << c << " " << "in sorted order is ";
cout << a1 << " " << b1 << " " << c1 << endl;
return 0;
}
void sort(int *x, int *y, int *z)
{
void change(int *i, int *j);
if (x>y)change(x, y);
if (x>z)change(x, z);
if (y>z)change(y, z);
}
void change(int *i, int *j)
{
int *f;
f = i;
i = j;
j = f;
}
不知道為什麼運行沒問題 可是就是比較不出結果
請賜教~
#include<iostream>
using namespace std;
void sort(int *x, int *y, int *z);
int main()
{
int a, b, c, a1, b1, c1;
cout << "Please enter 3 integers:";
cin >> a >> b >> c;
a1 = a, b1 = b, c1 = c;
sort(&a1, &b1,&c1);
cout << a << " " << b << " " << c << " " << "in sorted order is ";
cout << a1 << " " << b1 << " " << c1 << endl;
return 0;
}
void sort(int *x, int *y, int *z)
{
void change(int *i, int *j);
if (*x>*y)change(x, y);
if (*y>*z)change(y, z);
if (*x>*y)change(x, y);
}
void change(int *i, int *j)
{
int f;
f = *i;
*i = *j;
*j = f;
}