反序输出一个整数
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)//输入一个整数
{
int temp = 0;//temp作为存储的值
while (n != 0){
temp = temp * 10 + n % 10;
n /= 10;
} //反序取出来
cout << temp << endl; //打印
}
system("pause");
return 0;
}
运行结果:
选择排序
#include <iostream>
using namespace std;
void selectSort(int a[], int len)
{
int i, j, k, tem;
for (i = 0; i < len - 1; i++)
{
k = i;
for (j = k + 1; j < len; j++)
{
if (a[k] > a[j])
{
k = j;
}
}
if (i != k)
{
tem = a[i];
a[i] = a[k];
a[k] = tem;
}
}
}
int main()
{
int array[] = { 34, 65, 12, 43, 67, 5, 78, 10, 3, 70 }, k;
int len = sizeof(array) / sizeof(int);
cout << "The orginal array are:" << endl;
for (k = 0; k < len; k++)
cout << array[k] << ",";
cout << endl;
selectSort(array, len);
cout << "The sorted array are:" << endl;
for (k = 0; k < len; k++)
cout << array[k] << ",";
cout << endl;
system("pause");
return 0;
}